Skip to content
Snippets Groups Projects
Commit 61ac8056 authored by Svetlana Tkachenko's avatar Svetlana Tkachenko
Browse files

attempt to add dns, rpn plugins

parent bfb1fc06
No related branches found
No related tags found
No related merge requests found
# 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))
# 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment