Skip to content

Instantly share code, notes, and snippets.

@MarcoBuster
Last active June 9, 2019 12:59
Show Gist options
  • Save MarcoBuster/1d5d3307859017ccdd2bff06545b7d2c to your computer and use it in GitHub Desktop.
Save MarcoBuster/1d5d3307859017ccdd2bff06545b7d2c to your computer and use it in GitHub Desktop.
import botogram
import json
TOKEN = ''
bot = botogram.create(TOKEN)
def write(user, data):
with open(str(user.id) + ".json", "w+") as f:
json.dump(data, f)
def read(user):
try:
with open(str(user.id) + ".json", "r") as f:
return json.load(f)
except FileNotFoundError:
write(user, [])
return []
def add_p(user, p):
ps = read(user)
ps.append(p)
write(user, ps)
def del_p(user, i):
ps = read(user)
del ps[i]
write(user, ps)
@bot.command("nuovo")
def nuovo(message, args):
if not args:
message.reply("Devi specificare un proposito da aggiungere!")
add_p(message.sender, ' '.join(args))
message.reply("Fatto")
@bot.command("elimina")
def elimina(message, args):
if not args:
message.reply("Specifica il numero del proposito da eliminare")
del_p(message.sender, int(args[0])-1)
message.reply("Fatto")
@bot.command("propositi")
def propositi(message):
i = 1
text = "<b>I tuoi propositi</b>:"
for p in read(message.sender):
text += "\n{i}. {p}".format(i=i, p=p)
i+=1
message.reply(text, syntax="HTML")
bot.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment