Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- import json
- import string
- import os.path
- token = 'NjIzOTg2Njg5NDYzMDI1Njk0.XYKbAQ.5u-IY584CrUi3HReM7xe3MXZZDQ'
- bot = commands.Bot(command_prefix='!')
- @bot.command(name='charge', help='Total amount is charged to each person. Built in state of the art thief protection')
- async def charge(ctx, amount: float):
- if amount <= 0:
- ctx.message.add_reaction('<:no:426147595786649613>')
- await ctx.send('Positive values only')
- return
- for mention in ctx.message.mentions:
- transfer(ctx.author.name, mention.name, amount)
- await ctx.message.add_reaction('👍')
- @bot.command(name='split', help='Amount is split between each person. Built in state of the art thief protection')
- async def split(ctx, amount: float):
- if amount <= 0:
- ctx.message.add_reaction('<:no:426147595786649613>')
- await ctx.send('Positive values only')
- return
- for mention in ctx.message.mentions:
- transfer(ctx.author.name, mention.name, amount/len(ctx.message.mentions))
- await ctx.message.add_reaction('👍')
- @bot.command(name='credit', help='Pays the amount to that person')
- async def credit(ctx, amount: float):
- if amount <= 0:
- ctx.message.add_reaction('<:no:426147595786649613>')
- await ctx.send('Positive values only')
- return
- for mention in ctx.message.mentions:
- transfer(mention.name, ctx.author.name, amount)
- await ctx.message.add_reaction('👍')
- @bot.command(name='balance')
- async def balance(ctx):
- filepath = "%s.json" % ctx.author.name
- if os.path.exists(filepath):
- await ctx.send("No transactions found for %s" % ctx.author.name)
- else:
- with open("%s.json" % ctx.author.name) as json_file:
- data = json.load(json_file)
- await ctx.send("Balance for %s " % ctx.author.name + json.dumps(data))
- @bot.event
- async def on_ready():
- channel = bot.get_channel(620834829700825108)
- await channel.send('You gotta spend maney to make maney')
- print('Bot online')
- def transfer(nameToCredit: string, nameToCharge: string, amount: float):
- nameToCreditJsonFilePath = "%s.json" % nameToCredit
- nameToChargeJsonFilePath = "%s.json" % nameToCharge
- if os.path.exists(nameToCreditJsonFilePath):
- with open(nameToCreditJsonFilePath) as read_file:
- data = json.load(read_file)
- data[nameToCharge] -= amount
- with open(nameToCreditJsonFilePath, 'w') as write_file:
- json.dump(data, write_file)
- else:
- with open(nameToCreditJsonFilePath, 'w+') as write_file:
- data = {nameToCharge: amount * -1}
- json.dump(data, write_file)
- if os.path.exists(nameToChargeJsonFilePath):
- with open(nameToChargeJsonFilePath) as read_file:
- data = json.load(read_file)
- data[nameToCredit] += amount
- with open(nameToChargeJsonFilePath, 'w') as write_file:
- json.dump(data, write_file)
- else:
- with open(nameToChargeJsonFilePath, 'w+') as write_file:
- data = {nameToCredit: amount}
- json.dump(data, write_file)
- bot.run(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement