def first_write(self, poller, sock): self.logger.info("Sending initial info") self.send_message(irc.nick(self.conf.get_value("bot.nick"))) self.send_message(irc.user(self.conf.get_value("bot.nick"), self.conf.get_value("bot.realname"))) self.poller.remove_write(self.sock) self.poller.add_write(self.sock, self.write_socket) self.plugin_manager.handle_event(events.POST_CONNECT, [])
def connect (): try: irc.connect(irc.server, irc.port) except socket_error: # If the bot can't connect to the server, we get a socket error. print("WARNING: Couldn't connect to {}... (Retrying in 15 seconds.)".format(irc.server)) # Make irc.ircsock an object with recv and send methods. irc.ircsock = type("socket", (object,), { "recv": lambda *_: "", "send": lambda *_: "" })() # Wait for 15 seconds before attempting to reconnect. time.sleep(15) return # In case the connection to the server is successful... irc.display_info() irc.init() irc.ircsock.settimeout(irc.timeout) initial_nick = irc.botnick # In case the nickname throws errors. while tools.nick_check() and len(irc.botnick) < 20: # Append _ to botnick and try to reconnect. irc.botnick += "_" irc.nick(irc.botnick) # Check one last time for nick errors. if tools.nick_check(): print("ERROR: deskbot tried her best, but couldn't get in with any nicknames.") raise SystemExit elif irc.botnick != initial_nick: print("WARNING: Using nickname: {}".format(irc.botnick)) print("Joining channels: {}".format(" ".join(var.channels))) for channel in var.channels: irc.join(channel)
def init_connection(request): conf = request.source_settings username = conf.get('username') usermode = conf.get('usermode', 8) real_name = conf.get('real_name') password = conf.get('password') nick = conf.get('nick') commands = [irc.user(username, usermode, real_name), irc.nick(nick)] if password: commands.append(irc.password(password)) return commands
def irc_handshake(sock, nick, chan): # Stage 0: define what we're looking for in the transactions ident_trigger = "Checking Ident" join_trigger = "MODE" # Stage 1: send our ident once the server requests it while True: msg = receive(sock) if ident_trigger in msg: user_cmd = irc.user() # Formulate USER command transmit(sock, user_cmd) # Send USER command nick_cmd = irc.nick(nick) # Formulate NICK command transmit(sock, nick_cmd) # Send NICK command break # Stage 2: join channel once the server sets our mode while True: msg = receive(sock) # Check if the server has set a mode for us if join_trigger in msg: join_cmd = irc.join(chan) # Formulate JOIN command transmit(sock, join_cmd) # Send JOIN command break
port = 6697 bot_nick = "blackjackbot" password = "" bot_channel = "##blackjack" user_tracker = usertracker.UserTracker() with open("savefile", "r") as savefile: user_tracker.load_state(savefile) delay = .35 antiflood_timer = 0 antiflood_cooldown = 5 while True: irc = irc.Irc() irc.connect(host, port, True) irc.nick(bot_nick) irc.user(bot_nick) blackjack = None timer = 0 bantracker = ban.BanTracker() dd = False while True: irc.update_message_queue() if irc.message_queue == []: break