-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiscordMain.py
142 lines (91 loc) · 5.13 KB
/
discordMain.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
from functions import Functions
import discord
import os
class DiscordMain:
def run(token):
func = Functions()
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_message(message):
user = message.author.id
msg = message.content.split(' ')
if message.author == client.user:
return
elif message.content.startswith('!create'):
await message.channel.send('Create a new account\nPlease select a currency')
# Create a menu with the currencies
embed = discord.Embed(title="Currencies", description="Select a currency", color=0x00ff00)
embed.add_field(name="1", value="EUR", inline=False)
embed.add_field(name="2", value="USD", inline=False)
embed.add_field(name="3", value="Pound", inline=False)
embed.add_field(name="4", value="LPS", inline=False)
await message.channel.send(embed=embed)
# Wait for the user to select a currency
msg = await client.wait_for('message', check=lambda message: message.author == message.author)
# If the user selects a currency, create the account
if msg.content == '1':
dbMessage = func.createUser(message.author.id, 'EUR')
await message.channel.send(dbMessage)
elif msg.content == '2':
dbMessage = func.createUser(message.author.id, 'USD')
await message.channel.send(dbMessage)
elif msg.content == '3':
dbMessage = func.createUser(message.author.id, 'Pound')
await message.channel.send(dbMessage)
elif msg.content == '4':
dbMessage = func.createUser(message.author.id, 'LPS')
await message.channel.send(dbMessage)
elif message.content.startswith('!income'):
income = msg[1]
if len(msg) > 2:
description = msg[2]
else:
description = ''
dbMessage = func.addIncome(user, income, description)
await message.channel.send(dbMessage)
elif message.content.startswith('!expense'):
expense = msg[1]
if len(msg) > 2:
description = msg[2]
else:
description = ''
dbMessage = func.addExpense(user, expense, description)
await message.channel.send(dbMessage)
elif message.content.startswith('!balance'):
dbMessage = func.getBalance(user)
if dbMessage == "User doesn't exist" :
await message.channel.send(dbMessage)
return
embed = discord.Embed(title="Balance", description="Shows the total balance", color=0x00ff00)
embed.add_field(name="Total Balance", value=dbMessage, inline=False)
await message.channel.send(embed=embed)
elif message.content.startswith('!graph'):
if len(msg) > 1:
graphType = msg[1]
else:
graphType = '-bal'
dbMessage = func.getGraph(user, graphType)
if dbMessage == "User doesn't exist" :
await message.channel.send(dbMessage)
elif dbMessage == 'Graph created':
await message.channel.send(file=discord.File('plot.png'))
elif message.content.startswith('!delete'):
await message.channel.send('Are you sure you want to delete your account? (y/n)')
msg = await client.wait_for('message', check=lambda message: message.author == message.author)
if msg.content == 'y':
dbMessage = func.deleteUser(message.author.id)
await message.channel.send(dbMessage)
else:
await message.channel.send('Account not deleted')
elif message.content.startswith('!help'):
#Create an embed message
embed = discord.Embed(title="Help", description="List of commands", color=0x00ff00)
embed.add_field(name="!create", value="Create a new account", inline=False)
embed.add_field(name="!delete", value="Delete an account", inline=False)
embed.add_field(name="!income", value="Add an income", inline=False)
embed.add_field(name="!expense", value="Add an expense", inline=False)
embed.add_field(name="!balance", value="Get your balance", inline=False)
embed.add_field(name="!graph", value="Get a graph of your incomes, expenses (Use the word -in, -ex, -ba for print only one graph or -lm to print only the last month)", inline=False)
embed.add_field(name="!help", value="Get a list of commands", inline=False)
await message.channel.send(embed=embed)
client.run(token)