From 61ac8056e61af862cff2b363776525b301a81100 Mon Sep 17 00:00:00 2001 From: gry <guppy@123mail.org> Date: Fri, 17 Jun 2011 16:15:01 +0930 Subject: [PATCH] attempt to add dns, rpn plugins --- plugins/dns.py | 24 ++++++++++++++++++++++++ plugins/rpn.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 plugins/dns.py create mode 100644 plugins/rpn.py diff --git a/plugins/dns.py b/plugins/dns.py new file mode 100644 index 0000000..5967502 --- /dev/null +++ b/plugins/dns.py @@ -0,0 +1,24 @@ +# dns module +# --gry + +import urllib +import socket + +@plugin +class dns(object): + def __init__(self, server): + self.server = server + self.commands = ["dns"] + self.server.handle("command", self.handle_command, self.commands) + + def handle_command(self, channel, user, cmd, args): + if cmd == "dns": + if len(args) < 1: + self.server.doMessage(channel, user+": Return a fully qualified domain name for a list of space-separated IPs or hostnames.") + return + try: + for each in args: + self.server.doMessage(channel, user+": "+ each+" = "+socket.getfqdn(each)) + except Exception, e: + self.server.doMessage(channel, user+": "+str(e)) + diff --git a/plugins/rpn.py b/plugins/rpn.py new file mode 100644 index 0000000..16147fc --- /dev/null +++ b/plugins/rpn.py @@ -0,0 +1,42 @@ +# rpn module +# --gry + + +@plugin +class rpn(object): + def __init__(self, server): + self.server = server + self.commands = ["rpn"] + self.server.handle("command", self.handle_command, self.commands) + + def handle_command(self, channel, user, cmd, args): + if cmd == "rpn": + if len(args) < 1: + self.server.doMessage(channel, user+": reverse-polish-notation calculator. syntax: rpn 2 4 1 + / gives 2/5.") + return + self.stack = [] + for char in args: + try: + char = float(char)# if it succeeds, then char is a number + self.stack.append(char) + except Exception,e: #float(char) failed, it's nonsense or an operator + try: + a = float(self.stack.pop()) #last + b = float(self.stack.pop()) #pre-last + if(char == "+"): + self.stack.append(a + b) + elif(char == "-"): + self.stack.append(b - a) + elif(char == "^"): + self.stack.append(pow(b,a)) + elif(char == "*"): + self.stack.append(a * b) + elif(char == "/"): + self.stack.append(b / a) + except Exception, e: + self.conn.reply(str(e)) + return + try: + self.server.doMessage(channel, user+": "+str(self.stack[0])) + except Exception, e: + return -- GitLab