> HERE is a bot that uses the SingleServerIRCBot class from ircbot.py > The bot enters a channel and listens for commands in private messages or channel traffic. > Commands in channel messages are given by prefixing the text by the bot name followed by a colon.
> The known commands are: > stats -- Prints some channel information. > disconnect -- Disconnect the bot. The bot will try to reconnect after 60 seconds. > die -- Let the bot cease to exist. """ > now i programmed this below one i want to combine this one with ReaminderBot in JAVA with Ident server class can anybody help me in this regard > this python programmed below of Irc bot import string, random, re from ircbot import SingleServerIRCBot from irclib import nm_to_n, irc_lower def enforce_subset(set, subset): for item in subset: if (set.count(item) == 0): try: subset.remove(item) except: pass class TestBot(SingleServerIRCBot): def __init__(self, channel, nickname, server, port=6667): SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) self.channel = channel self.registered = [] self.random = random.Random() self.start() def on_welcome(self, c, e): c.join(self.channel) def on_join(self, c, e): c.privmsg("manager", "register") def on_privmsg(self, c, e): msg = re.sub(r'[^\s!-~\n]','', e.arguments()[0]) self.do_command(nm_to_n(e.source()), msg) def on_pubmsg(self, c, e): msg = re.sub(r'[^\s!-~\n]','', e.arguments()[0]) a = string.split(msg, ":", 1) b = string.split(msg, ",", 1) if len(a) > 1 and irc_lower(a[0].strip()) == irc_lower(self.connection.get_nickname()): self.do_command(nm_to_n(e.source()), string.strip(a[1])) elif len(b) > 1 and irc_lower(b[0].strip()) == irc_lower(self.connection.get_nickname()): self.message_manager(string.strip(b[1])) return def message_manager(self, message): c = self.connection reply = message c.privmsg("manager", reply) def do_command(self, nick, cmd): c = self.connection users = [] for chname, chobj in self.channels.items(): users.extend(chobj.users()) enforce_subset(users, self.registered) if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = chobj.users() users.sort() c.notice(nick, "Users: " + string.join(users, ", ")) opers = chobj.opers() opers.sort() c.notice(nick, "Opers: " + string.join(opers, ", ")) voiced = chobj.voiced() voiced.sort() c.notice(nick, "Voiced: " + string.join(voiced, ", ")) else: c.notice(nick, "Not understood: " + cmd) def main(): import sys if len(sys.argv) != 4: print "Usage: testbot <server[:port]> <channel> <nickname>" sys.exit(1) s = string.split(sys.argv[1], ":", 1) server = s[0] if len(s) == 2: try: port = int(s[1]) except ValueError: print "Error: Erroneous port." sys.exit(1) else: port = 6667 channel = sys.argv[2] nickname = sys.argv[3] bot = TestBot(channel, nickname, server, port) bot.start() if __name__ == "__main__": main() > now here is code of the ReminderBot > in java public class IdentServer extends Thread { /** * Constructs and starts an instance of an IdentServer that will * respond to a client with the provided login. Rather than calling * this constructor explicitly from your code, it is recommended that * you use the startIdentServer method in the IRCBot class. * <p> * The ident server will wait for up to 60 seconds before shutting * down. Otherwise, it will shut down as soon as it has responded * to an ident request. * * @param bot The IRCBot instance that will be used to log to. * @param login The login that the ident server will respond with. */ IdentServer(IRCBot bot, String login) { _bot = bot; _login = login; try { _ss = new ServerSocket(113); _ss.setSoTimeout(60000); } catch (Exception e) { _bot.log("*** Could not start the ident server on port 113."); return; } _bot.log("*** Ident server running on port 113 for the next 60 seconds..."); this.setName(this.getClass() + "-Thread"); this.start(); } /** * Waits for a client to connect to the ident server before making an * appropriate response. Note that this method is started by the class * constructor. */ public void run() { try { Socket socket = _ss.accept(); socket.setSoTimeout(60000); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); String line = reader.readLine(); if (line != null) { _bot.log("*** Ident request received: " + line); line = line + " : USERID : UNIX : " + _login; writer.write(line + "\r\n"); writer.flush(); _bot.log("*** Ident reply sent: " + line); writer.close(); } } catch (Exception e) { // We're not really concerned with what went wrong, are we? } try { _ss.close(); } catch (Exception e) { // Doesn't really matter... } _bot.log("*** The Ident server has been shut down."); } private IRCBot _bot; private String _login; private ServerSocket _ss = null; } > when i combined these two what exactly error comes it Gives me Reminder but only for Login any new person on IRC not Excatly about serversockets ? > any body can HELP me in this regards Regards Vikash Ruhil _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers