Fixed some formatting issues.
This commit is contained in:
parent
75f6dd6f4c
commit
e869bc4add
@ -46,8 +46,7 @@ class Greet(callbacks.Plugin):
|
|||||||
|
|
||||||
# Log event for debugging
|
# Log event for debugging
|
||||||
if self.debugMode:
|
if self.debugMode:
|
||||||
self._logDebug(irc, f"JOIN event detected: {nick} joined
|
self._logDebug(irc, f"JOIN event detected: {nick} joined {channel}")
|
||||||
{channel}")
|
|
||||||
|
|
||||||
# Don't greet ourselves
|
# Don't greet ourselves
|
||||||
if nick == irc.nick:
|
if nick == irc.nick:
|
||||||
@ -71,27 +70,22 @@ class Greet(callbacks.Plugin):
|
|||||||
# Check if we've already greeted this user with this greeting
|
# Check if we've already greeted this user with this greeting
|
||||||
userKey = f"{nick.lower()}@{channel}"
|
userKey = f"{nick.lower()}@{channel}"
|
||||||
|
|
||||||
if userKey in self.greetedUsers and channel in
|
if userKey in self.greetedUsers and channel in self.greetedUsers[userKey]:
|
||||||
self.greetedUsers[userKey]:
|
# If the greeting has changed since we last greeted this user, we should greet them again
|
||||||
# If the greeting has changed since we last greeted this user, we
|
|
||||||
# should greet them again
|
|
||||||
lastGreetingUsed = self.userGreetingVersion.get(userKey, "")
|
lastGreetingUsed = self.userGreetingVersion.get(userKey, "")
|
||||||
if greeting == lastGreetingUsed:
|
if greeting == lastGreetingUsed:
|
||||||
if self.debugMode:
|
if self.debugMode:
|
||||||
self._logDebug(irc, f"User {nick} already greeted in this
|
self._logDebug(irc, f"User {nick} already greeted in this session with current greeting")
|
||||||
session with current greeting")
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if self.debugMode:
|
if self.debugMode:
|
||||||
self._logDebug(irc, f"Greeting for {channel} has changed,
|
self._logDebug(irc, f"Greeting for {channel} has changed, will greet {nick} again")
|
||||||
will greet {nick} again")
|
|
||||||
|
|
||||||
# Get the timeout
|
# Get the timeout
|
||||||
timeout = self.registryValue('timeout', channel) or 3
|
timeout = self.registryValue('timeout', channel) or 3
|
||||||
|
|
||||||
if self.debugMode:
|
if self.debugMode:
|
||||||
self._logDebug(irc, f"Will greet in {channel} after {timeout}s:
|
self._logDebug(irc, f"Will greet in {channel} after {timeout}s: {greeting}")
|
||||||
{greeting}")
|
|
||||||
|
|
||||||
# Mark this user as greeted in this channel
|
# Mark this user as greeted in this channel
|
||||||
if userKey not in self.greetedUsers:
|
if userKey not in self.greetedUsers:
|
||||||
@ -104,8 +98,7 @@ will greet {nick} again")
|
|||||||
# Use a closure to capture the current values
|
# Use a closure to capture the current values
|
||||||
def sendGreeting(channelToGreet=channel, greetingMsg=greeting):
|
def sendGreeting(channelToGreet=channel, greetingMsg=greeting):
|
||||||
if self.debugMode:
|
if self.debugMode:
|
||||||
self._logDebug(irc, f"Sending greeting in {channelToGreet}:
|
self._logDebug(irc, f"Sending greeting in {channelToGreet}: {greetingMsg}")
|
||||||
{greetingMsg}")
|
|
||||||
try:
|
try:
|
||||||
# Make sure the channel is still valid when we send the message
|
# Make sure the channel is still valid when we send the message
|
||||||
if channelToGreet in irc.state.channels:
|
if channelToGreet in irc.state.channels:
|
||||||
@ -122,15 +115,13 @@ will greet {nick} again")
|
|||||||
try:
|
try:
|
||||||
# Send to the owner via private message instead of to a channel
|
# Send to the owner via private message instead of to a channel
|
||||||
for owner in self.registryValue('owners') or []:
|
for owner in self.registryValue('owners') or []:
|
||||||
irc.queueMsg(ircmsgs.privmsg(owner, f"[GREET-DEBUG]
|
irc.queueMsg(ircmsgs.privmsg(owner, f"[GREET-DEBUG] {message}"))
|
||||||
{message}"))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Fallback: send to the first available channel
|
# Fallback: send to the first available channel
|
||||||
for channel in list(irc.state.channels):
|
for channel in list(irc.state.channels):
|
||||||
try:
|
try:
|
||||||
irc.queueMsg(ircmsgs.privmsg(channel, f"[GREET-DEBUG]
|
irc.queueMsg(ircmsgs.privmsg(channel, f"[GREET-DEBUG] {message}"))
|
||||||
{message}"))
|
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
@ -215,11 +206,9 @@ greeted again
|
|||||||
self.setRegistryValue('enabled', True, channel)
|
self.setRegistryValue('enabled', True, channel)
|
||||||
greeting = self.registryValue('message', channel)
|
greeting = self.registryValue('message', channel)
|
||||||
if greeting:
|
if greeting:
|
||||||
irc.replySuccess(f"Greetings enabled for {channel}. Current
|
irc.replySuccess(f"Greetings enabled for {channel}. Current greeting: \"{greeting}\"")
|
||||||
greeting: \"{greeting}\"")
|
|
||||||
else:
|
else:
|
||||||
irc.error(f"Greetings enabled for {channel}, but no greeting
|
irc.error(f"Greetings enabled for {channel}, but no greeting message is set.")
|
||||||
message is set.")
|
|
||||||
|
|
||||||
@wrap(['channel'])
|
@wrap(['channel'])
|
||||||
def greetoff(self, irc, msg, args, channel):
|
def greetoff(self, irc, msg, args, channel):
|
||||||
@ -238,8 +227,7 @@ message is set.")
|
|||||||
"""
|
"""
|
||||||
self.setRegistryValue('message', '', channel)
|
self.setRegistryValue('message', '', channel)
|
||||||
self.setRegistryValue('enabled', False, channel)
|
self.setRegistryValue('enabled', False, channel)
|
||||||
irc.replySuccess(f"Greeting message cleared and disabled for
|
irc.replySuccess(f"Greeting message cleared and disabled for {channel}.")
|
||||||
{channel}.")
|
|
||||||
|
|
||||||
@wrap(['channel'])
|
@wrap(['channel'])
|
||||||
def greetstatus(self, irc, msg, args, channel):
|
def greetstatus(self, irc, msg, args, channel):
|
||||||
@ -256,15 +244,12 @@ message is set.")
|
|||||||
self.greetedUsers[userKey])
|
self.greetedUsers[userKey])
|
||||||
|
|
||||||
if enabled and message:
|
if enabled and message:
|
||||||
irc.reply(f"Greetings are enabled for {channel}. Timeout: {timeout}
|
irc.reply(f"Greetings are enabled for {channel}. Timeout: {timeout} seconds. Message: \"{message}\"")
|
||||||
seconds. Message: \"{message}\"")
|
|
||||||
irc.reply(f"Users greeted in this session: {greetedCount}")
|
irc.reply(f"Users greeted in this session: {greetedCount}")
|
||||||
elif enabled and not message:
|
elif enabled and not message:
|
||||||
irc.reply(f"Greetings are enabled for {channel}, but no message is
|
irc.reply(f"Greetings are enabled for {channel}, but no message is set.")
|
||||||
set.")
|
|
||||||
else:
|
else:
|
||||||
irc.reply(f"Greetings are disabled for {channel}. Message:
|
irc.reply(f"Greetings are disabled for {channel}. Message: \"{message or 'None'}\"")
|
||||||
\"{message or 'None'}\"")
|
|
||||||
|
|
||||||
@wrap(['channel', 'positiveInt'])
|
@wrap(['channel', 'positiveInt'])
|
||||||
def greettimeout(self, irc, msg, args, channel, seconds):
|
def greettimeout(self, irc, msg, args, channel, seconds):
|
||||||
@ -274,8 +259,7 @@ set.")
|
|||||||
Default is 3 seconds.
|
Default is 3 seconds.
|
||||||
"""
|
"""
|
||||||
self.setRegistryValue('timeout', seconds, channel)
|
self.setRegistryValue('timeout', seconds, channel)
|
||||||
irc.replySuccess(f"Greeting timeout for {channel} set to {seconds}
|
irc.replySuccess(f"Greeting timeout for {channel} set to {seconds} seconds.")
|
||||||
seconds.")
|
|
||||||
|
|
||||||
@wrap(['channel', 'text'])
|
@wrap(['channel', 'text'])
|
||||||
def greet(self, irc, msg, args, channel, text):
|
def greet(self, irc, msg, args, channel, text):
|
||||||
@ -321,11 +305,9 @@ again
|
|||||||
if userKey in self.userGreetingVersion:
|
if userKey in self.userGreetingVersion:
|
||||||
del self.userGreetingVersion[userKey]
|
del self.userGreetingVersion[userKey]
|
||||||
|
|
||||||
irc.replySuccess(f"Greeting message for {channel} set to:
|
irc.replySuccess(f"Greeting message for {channel} set to: \"{text}\" (greeting history reset)")
|
||||||
\"{text}\" (greeting history reset)")
|
|
||||||
else:
|
else:
|
||||||
irc.replySuccess(f"Greeting message for {channel} set to:
|
irc.replySuccess(f"Greeting message for {channel} set to: \"{text}\"")
|
||||||
\"{text}\"")
|
|
||||||
|
|
||||||
Class = Greet
|
Class = Greet
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user