circles/modules/stonks.py

94 lines
2.8 KiB
Python
Raw Normal View History

2020-02-07 16:37:52 +00:00
# load me
2020-02-07 16:50:01 +00:00
import json
def loadJson(self):
try:
2020-02-23 00:45:14 +00:00
with open('modules/stonks.json') as json_file:
2020-02-07 16:50:01 +00:00
data = json.load(json_file)
2020-02-23 00:45:14 +00:00
self.stonksData = data
2020-02-07 16:50:01 +00:00
except FileNotFoundError:
print('not found')
2020-02-23 00:45:14 +00:00
def writeJson(self):
with open('modules/stonks.json', 'w') as outfile:
json.dump(self.stonksData, outfile)
2020-02-07 16:50:01 +00:00
2020-02-23 00:45:14 +00:00
def createToken(self, c, n, m):
if ''.join(m) in self.stonksData:
self.say(c, 'that token already exists')
else:
m = ''.join(m)
self.stonksData[m] = {n: 100000}
self.say(c, 'token {} created!'.format(m))
def sendToken(self, c, n, m):
2020-02-23 11:50:37 +00:00
if self.stonksData[m[2]][n] - float(m[1]) >= 0 and float(m[1]) > 0:
2020-02-23 00:50:31 +00:00
try:
2020-02-23 11:50:37 +00:00
self.stonksData[m[2]][m[0]] += float(m[1])
2020-02-23 00:50:31 +00:00
except:
2020-02-23 11:50:37 +00:00
self.stonksData[m[2]][m[0]] = float(m[1])
self.stonksData[m[2]][n] += 0 - float(m[1])
2020-02-23 00:45:14 +00:00
self.say(c, 'sent!')
else:
self.say(c, 'invalid amount dummy thicc')
def listTokens(self, c, n, m):
self.say(c, 'the tokens that exist are '+' '.join(list(self.stonksData.keys())))
2020-02-23 19:12:49 +00:00
def nuke(self, c, n, m):
t = m.pop(0)
if self.stonksData[t][n] == 100000:
self.stonksData.pop(t)
self.say(c, 'removed token {}!'.format(t))
else:
self.say(c, 'you must own all of the token to delete it.')
2020-02-23 00:45:14 +00:00
def tokenBal(self, c, n, m):
2020-02-23 00:54:01 +00:00
if len(m) == 1:
try:
2020-02-23 18:54:39 +00:00
if m[0] == '*':
a=''
for i in [s for s in self.stonksData if n in self.stonksData[s]]:
a = a + "{}: {}, ".format(i, self.stonksData[i][n])
2020-03-05 15:41:29 +00:00
self.say(c, 'All your balances: {}'.format(a[:-2]))
2020-02-23 18:54:39 +00:00
return
2020-02-23 11:50:37 +00:00
self.say(c, "your balance of {} is {}.".format(m[0], self.stonksData[m[0]][n]))
2020-02-23 00:54:01 +00:00
except:
self.say(c, 'you have no {}.'.format(m[0]))
else:
try:
2020-02-23 11:50:37 +00:00
self.say(c, "{}'s balance of {} is {}.".format(m[0], m[1], self.stonksData[m[1]][m[0]]))
2020-02-23 00:54:01 +00:00
except:
self.say(c, '{} has no {}.'.format(m[0], m[1]))
2020-02-23 00:45:14 +00:00
cmds = {
"create": createToken,
"send": sendToken,
2020-02-23 00:56:26 +00:00
"tip": sendToken,
2020-02-23 00:45:14 +00:00
"tokens": listTokens,
"bal": tokenBal,
2020-02-23 19:12:49 +00:00
"balance": tokenBal,
"nuke": nuke
2020-02-23 00:45:14 +00:00
}
2020-02-07 16:50:01 +00:00
2020-02-07 16:37:52 +00:00
def parseCommand(self, c,n,m):
2020-02-23 00:45:14 +00:00
m = m.split()
m.pop(0)
cmd = m.pop(0)
if cmd in cmds:
loadJson(self)
cmds[cmd](self, c, n, m)
writeJson(self)
else:
2020-03-05 15:41:29 +00:00
self.say(c,'availible options are create <token>, send <recp> <amount> <token>, tokens, balance [user] <token>')
2020-02-07 16:37:52 +00:00
def init(self):
self.registerCommand('stonks', parseCommand)
2020-02-24 16:35:04 +00:00
self.registerCommand('stoinks', parseCommand)
self.registerCommand('stonk', parseCommand)
self.registerCommand('stocks', parseCommand)
2020-03-05 15:39:32 +00:00
self.registerHelp('stonks', 'stonks - fake cryptocurrency without a blockchain, do {}stonks help for syntax'.format(self.prefix))
2020-02-07 16:50:01 +00:00
2020-02-07 16:37:52 +00:00