-
Notifications
You must be signed in to change notification settings - Fork 5
Chat events
#How to use Chat Events on Renol IRC Bot
##Add a new function which will be executed on chat messages:
self.events["chat"].addEvent("ID of Function", Function)
Optionaly, you can pass on a list of channels on which the
function should operate, e.g.:
``self.events["chat"].addEvent("ID of Function", Function, ["#minecraft", "#mcdevs"])``
NOTE: The event function will be executed regardless of whether
the channel in which the message was received exists in the channel list.
Exceptions: Exceptions are raised in the following cases:
-
function is not callable: TypeError
-
FunctionID is already taken: EventAlreadyExists
-
Channel is not False or a list: TypeError
##When defining the function, it should look like this:
def chatEvent(self, channels, userdata, message, currChannel):
The function takes the arguments self, channels, userdata, message and currChannel.
- self is the commandHandler instance, it is necessary for using some functions
of Renol, e.g. the sendChatMessage function.
- channels is a list of the channels on which the function should operate.
If the list wasn't defined, channel will be False.
- userdata is a dictionary containing the name, ident and host of
the user who wrote the message. You can access them with
userdata["name"], userdata["ident"] and userdata["host"],
- message is a string containing the message sent by a user,
either directly or through a channel.
- currChannel is the channel on which the message was received.
If the message was sent to the bot privately, currChannel will be False.
##You can check if a Function ID is already in use or not with this:
self.events["chat"].doesExist("ID of Function")
False is returned if it doesn't exist, True is returned if it does exist.
##To remove a event function, you can use the following method:
self.events["chat"].removeEvent("ID of Function")
A KeyError is raised if the function does not exist.
##Add and remove channels from a event function using the following methods: self.events["chat"].addChannel("ID of Function", channel) self.events["chat"].removeChannel("ID of Function", channel)
-
Both methods raise a KeyError if the Function ID does not exist.
-
addChannel raises a ChannelAlreadyExists exception if the channel already exists.
-
channel needs to be a string, you can add one channel at a time right now.
##Get all the channels of a event function using the following method: self.events["chat"].getChannels("ID of Function") An empty list or a list of strings representing the channels you added will be returned.
##Additional Notes:
Use self.retrieveTrueCase(channel)
to get the true case of a channel name.
If the channel exists, a string will be returned with the correct case of the
channel name. The channel needs to be prefixed with a # or another channel symbol.
If the channel doesn't exist, False is returned.