forked from maxpowa/inumuta-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deadfish.py
53 lines (44 loc) · 1.44 KB
/
deadfish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# coding=utf-8
"""
deadfish.py - The fish are dead
Copyright 2014 Max Gurela
Licensed under the Eiffel Forum License 2.
"""
from __future__ import unicode_literals
from sopel.module import commands
import sys
if sys.version_info.major < 3:
str = unicode
chr = unichr
@commands('df', 'deadfish')
def deadfish(bot, trigger):
if not trigger.group(2):
return bot.say('[Deadfish] \'i\' increments, \'d\' decrements, \'o\' outputs, \'s\' squares, \'r\' resets. Prefix with -s to convert outputs to char representations.')
inp = trigger.group(2)
memory = 0
charoutput = False
if trigger.group(3).startswith('-'):
args = trigger.group(3)[1:]
if 's' in args:
charoutput = True
inp = trigger.group(2).lstrip(trigger.group(3)).strip()
output = []
for c in inp:
if memory == 256 or memory < 0 or memory > 9223372036859223372036854775807: # Synthetic max limit
memory = 0 # Overflow
if c == 'i':
memory += 1 # Increment
if c == 'd':
memory -= 1 # Decrement
if c == 'r':
memory = 0 # Inline reset (very handy)
if c == 'o':
output.append(memory) # Output
if c == 's':
memory *= memory # Square
outputstr = ' '.join(str(x) for x in output)
if charoutput:
outputstr = ''
for rep in output:
outputstr += chr(rep)
bot.say(outputstr)