allow one line rpn calculations

This commit is contained in:
vulpine 2020-08-05 15:02:58 -04:00
parent e6651438e7
commit cd6d6d1590
2 changed files with 26 additions and 25 deletions

View File

@ -16,33 +16,34 @@ async def rpninp(self, chan, nick, msg):
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(' '):
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