def on_ctcp(self, c, e): # event handler: ctcp if e.arguments()[0] == "VERSION": c.ctcp_reply(nm_to_n(e.source()), "VERSION " + "Rigs Of Rods server services and monitoring robot v" + self.main.settings.getSetting('general', 'version_str')) elif e.arguments()[0] == "PING": if len(e.arguments()) > 1: c.ctcp_reply(nm_to_n(e.source()), "PING " + e.arguments()[1])
def doCommand(self, channel, source, cmd): nickname = nm_to_n(source) a = cmd.split(" ", 1) a[0] = irc_lower(a[0].strip()) if a[0] == "!rawmsg": # server-admin only # send a chat message on the server if self.users.isServerAdmin(source, channel): if len(a)>1: self.main.messageRoRclientByChannel(channel, ("msg", a[1])) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!rawcmd": # server-admin only # send a chat message on the server if self.users.isServerAdmin(source, channel): if len(a)>1: self.main.messageRoRclientByChannel(channel, ("cmd", a[1])) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!msg": # send a chat message on the server if self.users.isServerAdmin(source, channel): if len(a)>1: self.main.messageRoRclientByChannel(channel, ("msg_with_source", a[1], nickname)) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!op": # send a chat message on the server if self.users.isServerAdmin(source, channel): if len(a)>1: self.server.send_raw("mode "+channel+" +o "+ a[1].lower()) self.notice(nickname, "'"+a[1]+"' is now a channel operator.", "syst") #self.notice(nickname, "mode "+channel+" +o "+ a[1].lower(), "syst") else: if nickname.lower() != 'lannii': self.server.send_raw("mode "+channel+" +o "+ nickname.lower()) self.notice(nickname, "You are now a channel operator.", "syst") #self.notice(nickname, "mode "+channel+" +o "+ nickname.lower(), "syst") else: self.notice(nickname, "You are already a channel operator.", "syst") else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!privmsg": # server-admin only # send a private chat message on the RoR server if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !privmsg <uid> <message>", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.msg(channel, "Syntax: !privmsg <uid> <message>", "syst") else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("privmsg", args[0], args[1])) else: self.msg(channel, "Syntax: !privmsg <uid> <message>", "syst") else: self.msg(channel, "Syntax: !privmsg <uid> <message>", "syst") else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!say": # server-admin only # send a chat message on the server, coming from 'host' if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !say [uid] <message>", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.main.messageRoRclientByChannel(channel, ("say", -1, a[1])) else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("say", args[0], args[1])) else: self.msg(channel, "Syntax: !say [uid] <message>", "syst") else: self.msg(channel, "Syntax: !say [uid] <message>", "syst") else: self.msg(channel, "You have no permission to use this command!", "syst") # elif a[0] == "!disconnect": # self.msg(channel, "Disconnecting on request...", "syst") # self.disconnect("As requested by %s" % nickname) elif a[0] == "!shutdown": # global-admin only # Shut down everything if self.users.isGlobalAdmin(source): self.msg(channel, "Initiating shutdown sequence...", "syst") self.main.messageMain(("IRC", "shut_down")) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!join": # global-admin only # join a channel on IRC if self.users.isGlobalAdmin(source): if len(a)>1: self.server.join(a[1]) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!leave": # global-admin only # leave a channel on IRC if self.users.isGlobalAdmin(source): if len(a)>1: self.server.part(a[1]) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!ping": # Easy command to check if the bot is online # (especially useful if you're using a znc) self.msg(channel, "pong", "funn") elif a[0] == "!kick": # server-admin only # kicks a player from the server if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !kick <uid> [reason]", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.msg(channel, "Syntax error, first parameter should be numeric (unique ID of user)", "syst") else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("kick", args[0], args[1])) elif len(args) ==1: self.main.messageRoRclientByChannel(channel, ("kick", args[0], "an unspecified reason")) else: self.msg(channel, "Syntax: !kick <uid> [reason]", "syst") else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!ban": # server-admin only # bans a player from the server if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !ban <uid> [reason]", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.msg(channel, "Syntax error, first parameter should be numeric (unique ID of user)", "syst") else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("ban", args[0], args[1])) elif len(args) ==1: self.main.messageRoRclientByChannel(channel, ("ban", args[0], "an unspecified reason")) else: self.msg(channel, "Syntax: !ban <uid> [reason]", "syst") else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!bans": # server-admin only # view currently banned people self.main.messageRoRclientByChannel(channel, ("msg", "!bans")) elif a[0] == "!list" : # returns a list of the players ingame self.main.messageRoRclientByChannel(channel, ("msg", "!list")) elif a[0] == "!pl" or a[0]=="!playerlist": self.main.messageRoRclientByChannel(channel, ("list_players",)) elif a[0] == "!info" or a[0] == "!gi": # returns the server info (name, ip, port, terrain, players, ...) self.main.messageRoRclientByChannel(channel, ("info", "full")) elif a[0] == "!stats": self.main.messageRoRclientByChannel(channel, ("global_stats",)) elif a[0] == "!pinfo" or a[0] == "!pi" or a[0] == "!playerinfo": # returns the player info if len(a) < 2: self.msg(channel, "Syntax: !pi <uid>", "syst") else: try: a[1] = int(a[1]) except ValueError: self.msg(channel, "Syntax error, first parameter should be numeric (unique ID of user)", "syst") else: self.main.messageRoRclientByChannel(channel, ("player_info", a[1])) elif a[0] == "!terrain": # returns the server info (name, terrain, players) self.main.messageRoRclientByChannel(channel, ("info", "short")) elif a[0] == "!ip" or a[0] == "!serverinfo" or a[0] == "!si": # returns the server name, ip and port self.main.messageRoRclientByChannel(channel, ("info", "ip")) elif a[0] == "!warn": # server-admin only # send a warning to a user if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !warn <uid> [reason]", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.msg(channel, "Syntax error, first parameter should be numeric (unique ID of user)", "syst") else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("say", args[0], args[1])) elif len(args) ==1: self.main.messageRoRclientByChannel(channel, ("say", args[0], "This is an official warning. Please read our rules using the !rules command.")) else: self.msg(channel, "Syntax: !warn <uid> [reason]", "syst") else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!disconnect": # server-admin only # disconnects from the a RoR server if self.users.isServerAdmin(source, channel): self.main.messageRoRclientByChannel(channel, ("disconnect", "Leaving server...")) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!connect": # server-admin only # connect to a RoR server if self.users.isServerAdmin(source, channel): self.main.messageMain(("IRC", "connect", channel)) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "!serverlist" or a[0] == "!servlist": # returns a list of RoR servers we're connected to (with ID, name, ip and port) CIFPO_serv | servername | players/maxplayers | online if self.users.isGlobalAdmin(source): self.main.messageMain(("IRC", "serverlist", channel)) else: self.msg(channel, "You have no permission to use this command!", "syst") elif a[0] == "identify": if channel == nickname: if len(a) < 2: self.notice(nickname, "Syntax: /msg %s IDENTIFY <username> <password>" % self.server.get_nickname(), "syst") else: args = a[1].split(" ") adminType = { 'adminName': "" } if len(args) >= 2 and self.users.adminLogIn(source, args[0], args[1], adminType): self.notice(nickname, "You are now identified as %s" % adminType['adminName'], "syst") elif len(args) >= 2: self.notice(nickname, "This user/password combination does not exist.", "syst") else: self.notice(nickname, "Syntax: /msg %s IDENTIFY <username> <password>" % self.server.get_nickname(), "syst") elif a[0] == "logout": if channel == nickname: if self.users.adminLogOut(source): self.notice(nickname, "You are now logged out.", "syst") else: self.notice(nickname, "You weren't logged in :/", "syst") elif a[0] == "!admins": if self.users.isGlobalAdmin(source): admins = self.users.getAdmins() self.notice(nickname, "nickname | username | channel", "syst") for type in admins.keys(): for nick in admins[type].keys(): if admins[type][nick]['identified']: self.notice(nickname, "%-11s| %-11s| %s" % (nm_to_n(nick), admins[type][nick]['username'], type), "syst") else: self.notice(nickname, "Please login first.", "syst") elif a[0] == "!fps": self.main.messageRoRclientByChannel(channel, ("fps", ""))
def on_pubnotice(self, c, e): # event handler: pubnotice self.logger.debug("%s: %s: %s", e.target(), nm_to_n(e.source()), e.arguments()[0]) self.doCommand(irc_lower(e.target()), e.source(), e.arguments()[0])
def on_privmsg(self, c, e): # event handler: privmsg self.logger.debug("%s: %s: %s", e.target(), nm_to_n(e.source()), e.arguments()[0]) self.doCommand(nm_to_n(e.source()), e.source(), e.arguments()[0])
def doCommand(self, channel, source, cmd): nickname = nm_to_n(source) a = cmd.split(" ", 1) a[0] = irc_lower(a[0].strip()) if a[0] == "!rawmsg": # server-admin only # send a chat message on the server if self.users.isServerAdmin(source, channel): if len(a)>1: self.main.messageRoRclientByChannel(channel, ("msg", a[1])) else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!rawcmd": # server-admin only # send a chat message on the server if self.users.isServerAdmin(source, channel): if len(a)>1: self.main.messageRoRclientByChannel(channel, ("cmd", a[1])) else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!msg": # send a chat message on the server if len(a)>1: self.main.messageRoRclientByChannel(channel, ("msg_with_source", a[1], nickname)) else: self.notice(nickname, "Syntax: !msg <message>", "syst") elif a[0] == "!op": # send a chat message on the server if self.users.isServerAdmin(source, channel): if len(a)>1: self.server.send_raw("mode "+channel+" +o "+ a[1].lower()) self.notice(nickname, "'"+a[1]+"' is now a channel operator.", "syst") #self.notice(nickname, "mode "+channel+" +o "+ a[1].lower(), "syst") else: if nickname.lower() != 'lannii': self.server.send_raw("mode "+channel+" +o "+ nickname.lower()) self.notice(nickname, "You are now a channel operator.", "syst") #self.notice(nickname, "mode "+channel+" +o "+ nickname.lower(), "syst") else: self.notice(nickname, "You are already a channel operator.", "syst") else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!privmsg": # server-admin only # send a private chat message on the RoR server if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !privmsg <uid> <message>", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.msg(channel, "Syntax: !privmsg <uid> <message>", "syst") else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("privmsg", args[0], args[1])) else: self.msg(channel, "Syntax: !privmsg <uid> <message>", "syst") else: self.msg(channel, "Syntax: !privmsg <uid> <message>", "syst") else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!say": # server-admin only # send a chat message on the server, coming from 'host' if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !say [uid] <message>", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.main.messageRoRclientByChannel(channel, ("say", -1, a[1])) else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("say", args[0], args[1])) else: self.msg(channel, "Syntax: !say [uid] <message>", "syst") else: self.msg(channel, "Syntax: !say [uid] <message>", "syst") else: self.notice(nickname, "You have no permission to use this command!", "syst") # elif a[0] == "!disconnect": # self.msg(channel, "Disconnecting on request...", "syst") # self.disconnect("As requested by %s" % nickname) elif a[0] == "!shutdown": # global-admin only # Shut down everything if self.users.isGlobalAdmin(source): self.msg(channel, "Initiating shutdown sequence...", "syst") self.main.messageMain(("IRC", "shut_down")) else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!join": # global-admin only # join a channel on IRC if self.users.isGlobalAdmin(source): if len(a)>1: self.server.join(a[1]) else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!leave": # global-admin only # leave a channel on IRC if self.users.isGlobalAdmin(source): if len(a)>1: self.server.part(a[1]) else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!ping": # Easy command to check if the bot is online # (especially useful if you're using a znc) self.msg(channel, "pong", "funn") elif a[0] == "!kick": # server-admin only # kicks a player from the server if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !kick <uid> [reason]", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.msg(channel, "Syntax error, first parameter should be numeric (unique ID of user)", "syst") else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("kick", args[0], args[1])) elif len(args) ==1: self.main.messageRoRclientByChannel(channel, ("kick", args[0], "an unspecified reason")) else: self.msg(channel, "Syntax: !kick <uid> [reason]", "syst") else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!ban": # server-admin only # bans a player from the server if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !ban <uid> [reason]", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.msg(channel, "Syntax error, first parameter should be numeric (unique ID of user)", "syst") else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("ban", args[0], args[1])) elif len(args) ==1: self.main.messageRoRclientByChannel(channel, ("ban", args[0], "an unspecified reason")) else: self.msg(channel, "Syntax: !ban <uid> [reason]", "syst") else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!bans": # server-admin only # view currently banned people self.main.messageRoRclientByChannel(channel, ("msg", "!bans")) elif a[0] == "!list" : # returns a list of the players ingame self.main.messageRoRclientByChannel(channel, ("msg", "!list")) elif a[0] == "!pl" or a[0]=="!playerlist": self.main.messageRoRclientByChannel(channel, ("list_players",)) elif a[0] == "!info" or a[0] == "!gi": # returns the server info (name, ip, port, terrain, players, ...) self.main.messageRoRclientByChannel(channel, ("info", "full")) elif a[0] == "!stats": self.main.messageRoRclientByChannel(channel, ("global_stats",)) elif a[0] == "!pinfo" or a[0] == "!pi" or a[0] == "!playerinfo": # returns the player info if len(a) < 2: self.msg(channel, "Syntax: !pi <uid>", "syst") else: try: a[1] = int(a[1]) except ValueError: self.msg(channel, "Syntax error, first parameter should be numeric (unique ID of user)", "syst") else: self.main.messageRoRclientByChannel(channel, ("player_info", a[1])) elif a[0] == "!terrain": # returns the server info (name, terrain, players) self.main.messageRoRclientByChannel(channel, ("info", "short")) elif a[0] == "!ip" or a[0] == "!serverinfo" or a[0] == "!si": # returns the server name, ip and port self.main.messageRoRclientByChannel(channel, ("info", "ip")) elif a[0] == "!warn": # server-admin only # send a warning to a user if self.users.isServerAdmin(source, channel): if len(a) < 2: self.msg(channel, "Syntax: !warn <uid> [reason]", "syst") else: args = a[1].split(" ", 1) if len(args) >= 1: try: args[0] = int(args[0]) except ValueError: self.msg(channel, "Syntax error, first parameter should be numeric (unique ID of user)", "syst") else: if len(args) ==2: self.main.messageRoRclientByChannel(channel, ("say", args[0], args[1])) elif len(args) ==1: self.main.messageRoRclientByChannel(channel, ("say", args[0], "This is an official warning. Please read our rules using the !rules command.")) else: self.msg(channel, "Syntax: !warn <uid> [reason]", "syst") else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!disconnect": # server-admin only # disconnects from the a RoR server if self.users.isServerAdmin(source, channel): self.main.messageRoRclientByChannel(channel, ("disconnect", "Leaving server...")) else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!connect": # server-admin only # connect to a RoR server if self.users.isServerAdmin(source, channel): self.main.messageMain(("IRC", "connect", channel)) else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "!irckick": # server-admin only # kicks someone out of the IRC channel pass elif a[0] == "!ircban": # server-admin only # bans and kicks someone from the IRC channel pass elif a[0] == "!ircunban": # server-admin only # unbans someone from the IRC channel pass elif a[0] == "!serverlist" or a[0] == "!servlist": # returns a list of RoR servers we're connected to (with ID, name, ip and port) CIFPO_serv | servername | players/maxplayers | online if self.users.isGlobalAdmin(source): self.main.messageMain(("IRC", "serverlist", channel)) else: self.notice(nickname, "You have no permission to use this command!", "syst") elif a[0] == "identify": if channel == nickname: if len(a) < 2: self.notice(nickname, "Syntax: /msg %s IDENTIFY <username> <password>" % self.server.get_nickname(), "syst") else: args = a[1].split(" ") adminType = { 'adminName': "" } if len(args) >= 2 and self.users.adminLogIn(source, args[0], args[1], adminType): self.notice(nickname, "You are now identified as %s" % adminType['adminName'], "syst") elif len(args) >= 2: self.notice(nickname, "This user/password combination does not exist.", "syst") else: self.notice(nickname, "Syntax: /msg %s IDENTIFY <username> <password>" % self.server.get_nickname(), "syst") elif a[0] == "logout": if channel == nickname: if self.users.adminLogOut(source): self.notice(nickname, "You are now logged out.", "syst") else: self.notice(nickname, "You weren't logged in :/", "syst") elif a[0] == "!admins": if self.users.isGlobalAdmin(source): admins = self.users.getAdmins() self.notice(nickname, "nickname | username | channel", "syst") for type in admins.keys(): for nick in admins[type].keys(): if admins[type][nick]['identified']: self.notice(nickname, "%-11s| %-11s| %s" % (nm_to_n(nick), admins[type][nick]['username'], type), "syst") else: self.notice(nickname, "Please login first.", "syst") elif a[0] == "!fps": self.main.messageRoRclientByChannel(channel, ("fps", ""))