@CalebEvans1/

TestBot

Python

No description

fork
loading
Files
  • main.py
  • keep_alive.py
  • requirements.txt
  • text.json
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import  os, random, base64, json
import discord
from pprint import pprint

import time

print("Retrieved Libraries")

#Get all of the .env variables
TOKEN = os.getenv('token')
Pass = os.getenv('dbupass')
UName = os.getenv('dbuname')
print("Retrieved Variables")

#Initialize the SQL connection
from mysqldb import MySQLdb
db = MySQLdb.connect(host="remotemysql.com",  # your host 
                     user=UName,       # username
                     passwd=Pass,     # password
                     db=UName)   # name of the database
cur = db.cursor()
print("Created the link")

CURRENCY_DATA = json.load(open("text.json", 'r'))

for i in CURRENCY_DATA["Users"]:
    cur.execute('INSERT INTO Users (DiscordID) VALUES ({0});')

yee = discord.Client()

@yee.event
async def on_ready():
  await yee.send_message(yee.get_channel('558024841572253706'), "Ready")
  await yee.change_presence(game=discord.Game(name="use b!help for help!"))
  
message_log = []

@yee.event
async def on_message(message):
  if message.author == yee.user:
    return
  
  if message.content.startswith('b!hello'):
    msg = "Hello, {0.author.mention}".format(message)
    await yee.send_message(message.channel, msg)
    return
  
  if message.content.startswith('b!invite'):
    msg = "{0.author.mention} Go to https://discordapp.com/oauth2/authorize?client_id=555115104769933383&scope=bot".format(message)
    await yee.send_message(message.channel, msg)
    return
  
  if message.content.startswith('b!help'):
    msg = "{0.author.mention}\n```\nb!hello - say hello to the bot!\nb!invite - invite me to your server!\nb!help - You just used this command!".format(message)
    msg += "\nb!luckynumber - gives you a lucky number!\nb!bal - look at how many testcoin you have\nb!shop - look at the various money genorators that you can/can't buy!\n"
    msg += "b!buy <x> - use to buy generator with a purchase ID of x (remove the brackets)\n```"
    await yee.send_message(message.channel, msg)
    return
  
  if message.content.startswith('b!luckynumber'):
    msg = "{0.author.mention} Your lucky number is ".format(message) + str(random.randint(0,9999))
    await yee.send_message(message.channel, msg)
    return

  if message.content.startswith('b!bal'):
    if str(message.author.id) not in CURRENCY_DATA["Users"]:
      CURRENCY_DATA["Money"][str(message.author.id)] = 0.0001
      CURRENCY_DATA["Updates"][str(message.author.id)] = time.time()
      CURRENCY_DATA["Money Inventory"][str(message.author.id)] = [0,0,0]
      CURRENCY_DATA["Users"].append(str(message.author.id))
      CURRENCY_DATA["Inventory"][str(message.author.id)] = []
    for i in range(len(CURRENCY_DATA["Money Generators"])):
        CURRENCY_DATA["Money"][str(message.author.id)] += round(CURRENCY_DATA["Money Inventory"][str(message.author.id)][i] * CURRENCY_DATA["Money Generators"][i]["CPS"] * (time.time() - CURRENCY_DATA["Updates"][str(message.author.id)]), 5)
    CURRENCY_DATA["Updates"][str(message.author.id)] = time.time()
    CURRENCY_DATA["Money"][str(message.author.id)] = round(CURRENCY_DATA["Money"][str(message.author.id)], 5)
    msg = "{0.author.mention}, You have {1} TestCoin.".format(message, CURRENCY_DATA["Money"][str(message.author.id)])
    await yee.send_message(message.channel, msg)
    json.dump(CURRENCY_DATA, open('text.json','w'))
    return

  if message.content.startswith('b!shop'):
      if str(message.author.id) not in CURRENCY_DATA["Users"]:
        CURRENCY_DATA["Money"][str(message.author.id)] = 0.0001
        CURRENCY_DATA["Updates"][str(message.author.id)] = time.time()
        CURRENCY_DATA["Money Inventory"][str(message.author.id)] = [0,0,0]
        CURRENCY_DATA["Users"].append(str(message.author.id))
        CURRENCY_DATA["Inventory"][str(message.author.id)] = []
      for i in range(len(CURRENCY_DATA["Money Generators"])):
        CURRENCY_DATA["Money"][str(message.author.id)] += round(CURRENCY_DATA["Money Inventory"][str(message.author.id)][i] * CURRENCY_DATA["Money Generators"][i]["CPS"] * (time.time() - CURRENCY_DATA["Updates"][str(message.author.id)]), 5)
      CURRENCY_DATA["Updates"][str(message.author.id)] = time.time()
      msg = "{0.author.mention}, You have {1} TestCoin.".format(message, CURRENCY_DATA["Money"][str(message.author.id)])
      msg += '\n```\n'
      for i in CURRENCY_DATA["Money Generators"]:
          msg += i['name'] + ' $'
          msg += str(i['increase_amount'] * (1 + CURRENCY_DATA["Money Inventory"][str(message.author.id)][i['id']]) * i['base_price']) + '\n'
          msg += i['info'] + '\n'
          msg += 'Purchase code: ' + str(i['id']) + '\n\n'
      msg += '\n```'
      await yee.send_message(message.channel, msg)
      json.dump(CURRENCY_DATA, open('text.json', 'w'))
      return
  
  if message.content.startswith('b!buy'):
      for i in range(len(CURRENCY_DATA["Money Generators"])):
        CURRENCY_DATA["Money"][str(message.author.id)] += round((1 + CURRENCY_DATA["Money Inventory"][str(message.author.id)][i]) * CURRENCY_DATA["Money Generators"][i]["CPS"] * (time.time() - CURRENCY_DATA["Updates"][str(message.author.id)]), 5)
      CURRENCY_DATA["Updates"][str(message.author.id)] = time.time()
      buy_id = message.content[5:]
      try:
          try:
              adjusted_cost = CURRENCY_DATA["Money Generators"][int(buy_id)]["base_price"] * (CURRENCY_DATA["Money Generators"][int(buy_id)]['increase_amount'] * CURRENCY_DATA["Money Inventory"][str(message.author.id)][int(buy_id)])
          except ValueError:
              await yee.send_message(message.channel, "The value of the generator you are trying to buy could not be converted. please try again using the purchase code of the generator you want to buy.")
              return
      except IndexError:
          await yee.send_message(message.channel, "The purchase id is not valid")
          return
      if CURRENCY_DATA["Money"][str(message.author.id)] >= adjusted_cost:
          CURRENCY_DATA["Money"][str(message.author.id)] -= adjusted_cost
          CURRENCY_DATA["Money Inventory"][str(message.author.id)][int(buy_id)] += 1
          await yee.send_message(message.channel, "Purchase successful.")
          return
      else:
          await yee.send_message(message.channel, "Error, not enough funds")
          return
  
  if message.content.startswith('[email protected]') and message.author.id == ADMIN_ID:
    if message.content.startswith('[email protected]'):
      msg = '```\n'
      channels = yee.get_all_channels()
      a = 0
      for i in channels:
        msg += str(i.name).ljust(25,'-') + str(i.id).ljust(25,'-') + str(i.server) + '\n'
        a += 1
        if a > 19:
          await yee.send_message(message.channel, msg+'```')
          a = 0
          msg = '```\n'
      msg += '```'
      print(msg)
      await yee.send_message(message.channel, msg)
      return
  else:
    if message.content.startswith('[email protected]'):
      await yee.send_message(message.channel, message.author.mention + ', you do not have access to this command!')


#yee.run(TOKEN)