def on_ping(self, connection, event): self.last_ping = 0 try: db = pierc_db.Pierc_DB(self.mysql_server, self.mysql_port, self.mysql_database, self.mysql_user, self.mysql_password) for message in self.message_cache: db.insert_line(message["channel"], message["name"], message["time"], message["message"], message["type"]) db.commit() if self.disconnect_countdown < 5: self.disconnect_countdown = self.disconnect_countdown + 1 del db # clear the cache self.message_cache = [] except Exception as e: print("Database Commit Failed! Let's wait a bit!") print(e) if self.disconnect_countdown <= 0: sys.exit(0) connection.privmsg( self.channel, "Database connection lost! " + str(self.disconnect_countdown) + " retries until I give up entirely!") self.disconnect_countdown = self.disconnect_countdown - 1
def on_join(self, connection, event): """Say hello to other people in the channel. """ connection.privmsg( self.__config.CHANNEL, "Hi, I'm " + Colours('3', str(connection.get_nickname())).get() + " your bot. Send " + Colours(self.num_col, "!help").get() + " to get a list of commands.") self.__on_connect_cb()
def on_nicknameinuse(self, connection, event): """Changes the nickname if necessary""" print("Nick in use") if not self.__config.NICKSERV_PASSWORD: connection.nick(connection.get_nickname() + "_") else: print("Ghosting nick") #connection.nick(self.__config.NICK) msg = "GHOST {} {}".format(self.__config.NICK, self.__config.NICKSERV_PASSWORD) connection.privmsg("NICKSERV", msg)
def on_join(self, connection, event): """Say hello to other people in the channel. """ welcome_msg = "Hi, I'm " + self.__get_colored_text('3',str(connection.get_nickname())) + " your bot. Send " + self.__get_colored_text(self.color_num,"!help") +" to get a list of commands." if not self.__first_start: connection.privmsg(self.__config.CHANNEL, welcome_msg) self.__on_connect_cb() self.__first_start = True if event.source.nick != connection.get_nickname(): connection.privmsg(event.source.nick, welcome_msg)
def on_pubmsg(self, connection, event): text = event.arguments[0] # If you talk to the bot, this is how he responds. if self.nick_reg.search(text): if text.split(" ")[1] and text.split(" ")[1] == "quit": connection.privmsg(self.channel, "Goodbye.") self.on_ping(connection, event) sys.exit(0) if text.split(" ")[1] and text.split(" ")[1] == "ping": self.on_ping(connection, event) return
def on_welcome(self, connection, event): """ Join the correct channel upon connecting. This runs when we first join the IRC server. """ if self.__config.NICKSERV_PASSWORD: print("Identifying for nick", self.__config.NICK) msg = "IDENTIFY {} {}".format(self.__config.NICK, self.__config.NICKSERV_PASSWORD) connection.privmsg("NICKSERV", msg) # make sure we join chans as the last thing if irc.client.is_channel(self.__config.CHANNEL): connection.join(self.__config.CHANNEL)
def on_welcome(self, connection, event): """Handle welcome message from server.""" if self.nickserv_password: print('Identifying with NickServ...') # TODO(dolph): should wait for nickserv response before joining a # channel that might require it. connection.privmsg( 'NickServ', 'IDENTIFY %s %s' % ( self.nickname, self.nickserv_password)) print('Joining %s...' % self.channel) connection.join(self.channel) print('Requesting names on channel...') connection.names(self.channel) # Disconnect later, after the standup is over. print('Disconnecting after %d seconds.' % self.standup_duration) connection.execute_delayed( delay=self.standup_duration, function=self.end_standup)
def on_invite(self, connection: ServerConnection, event: Event): if not isinstance(event.source, irc.client.NickMask): return nick = event.source.nick channel = self._lowercase(event.arguments[0]) _logger.info('Received invite from %s to %s', nick, channel) whitelisted_channels = split_list_option( self._config['pleaseopme']['whitelist']) whitelisted_channels = tuple(map(self._lowercase, whitelisted_channels)) max_channels = self._config['pleaseopme'].getint('max_channels', None) if not whitelisted_channels or channel in whitelisted_channels: current_num_channels = self._channel_tracker.count() if max_channels and current_num_channels >= max_channels: connection.privmsg(nick, 'Too many channels.') else: _logger.info('Join channel %s by %s', channel, nick) connection.privmsg(nick, 'Joining channel {0}'.format(channel)) connection.join(channel) connection.who(channel) self._channel_tracker.add(channel) else: connection.privmsg(nick, 'Channel is not whitelisted.')
def on_namreply(self, connection, event): """Start the standup.""" # Bail if we've already started a standup. if self._already_started_standup: return self._already_started_standup = True # The list of names is space-delimited. Break it apart so we can # iterate through it. list_of_names = event.arguments[-1].split(' ') # Strip user modes from names. list_of_names = [x.lstrip('@').lstrip('+') for x in list_of_names] # Filter list of names for ones we care about. list_of_names = [x for x in list_of_names if x in self.users_to_ping] # Build a pretty ping message. message = '' if list_of_names: message = ', '.join(sorted(list_of_names)) message += ': ' message += self.topic # Send the standup ping. connection.privmsg(self.channel, message) connection.privmsg(self.channel, 'What are you working on today, and ' 'what do you need help with?') # Ping the users that are not in the channel privately. for user in self.users_to_ping: if user not in list_of_names: connection.privmsg( user, '%s in %s' % (self.topic, self.channel))
def reply(message: str): connection.privmsg(channel, '{}: {}'.format(nick, message))
def reply(message: str): connection.privmsg(nick, message)
def main_loop(connection): connection.privmsg(self.channel, msg) connection.quit("Bye !")
def login(self, connection): # TODO add more login ways if self.password is not None: connection.privmsg( 'NickServ', 'identify %s %s' % (self.connection.get_nickname(), self.password))