Compare commits

...

2 Commits

Author SHA1 Message Date
vulpine 8f035e1c18 fix running out of registers on combined rpn 2020-08-05 19:03:02 -04:00
vulpine cd6d6d1590 allow one line rpn calculations 2020-08-05 15:02:58 -04:00
2 changed files with 28 additions and 27 deletions

View File

@ -13,36 +13,37 @@ def isfloat(value):
async def rpninp(self, chan, nick, msg):
if chan not in self.rpnhist:
self.rpnhist[chan] = [0]
self.rpnhist[chan].append(0)
del self.rpnhist[chan][15:]
try:
if isfloat(msg):
self.rpnhist[chan].insert(0, float(msg))
return
elif msg == '+' or msg == 'a':
self.rpnhist[chan][0] = self.rpnhist[chan][0]+self.rpnhist[chan].pop(1)
elif msg == '-' or msg == 's':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)-self.rpnhist[chan][0]
elif msg == '*' or msg == 'x' or msg == 'm':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)*self.rpnhist[chan][0]
for m in msg.split(' '):
self.rpnhist[chan].append(0)
del self.rpnhist[chan][15:]
if isfloat(m):
self.rpnhist[chan].insert(0, float(m))
continue
elif m == '+' or m == 'a':
self.rpnhist[chan][0] = self.rpnhist[chan][0]+self.rpnhist[chan].pop(1)
elif m == '-' or m == 's':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)-self.rpnhist[chan][0]
elif m == '*' or m == 'x' or m == 'm':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)*self.rpnhist[chan][0]
elif msg == '/' or msg == 'd':
try:
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)/self.rpnhist[chan][0]
except ZeroDivisionError:
self.rpnhist[chan][0] = float('NaN')
elif m == '/' or m == 'd':
try:
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)/self.rpnhist[chan][0]
except ZeroDivisionError:
self.rpnhist[chan][0] = float('NaN')
elif msg == '^' or msg == 'e':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)**self.rpnhist[chan][0]
elif m == '^' or m == 'e':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)**self.rpnhist[chan][0]
elif msg == 'p':
pass # just dont do anything lol
elif msg == 'r':
if chan in self.rpnprint:
await self.message(chan, '[\x036rpn\x0f] {}'.format(str(self.rpnhist[chan])))
return
else:
return
elif msg == 'p':
pass # just dont do anything lol
elif msg == 'r':
if chan in self.rpnprint:
await self.message(chan, '[\x036rpn\x0f] {}'.format(str(self.rpnhist[chan])))
return
else:
return
except OverflowError:
if chan in self.rpnprint:
await self.message(chan, '[\x036rpn\x0f] no u ur numbers are too phat')

View File

@ -2,7 +2,7 @@
Description=oirc bot
[Service]
ExecStart=/bin/sh -c 'source /home/xfnw/env/bin/activate; cd /home/xfnw/oirc-bot/; PYTHONUNBUFFERED=1 ./bot.py'
ExecStart=/bin/sh -c 'cd /home/xfnw/oirc-bot/; PYTHONUNBUFFERED=1 ./bot.py'
[Install]
WantedBy=default.target