-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDiscordConnect.py
92 lines (77 loc) · 2.94 KB
/
DiscordConnect.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
# Work with Python 3.6
import discord
import json
import WebScrape
import GenerateGraph
from discord import File
with open('Secret.json') as json_file:
data = json.load(json_file)
TOKEN = data['discordKey']
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hello'):
msg = 'Hello {0.author.mention}'.format(message)
# await message.channel.send(msg)
testFile = File('options.csv')
await message.channel.send(file = testFile)
elif message.content.startswith('!recordanewmixtape'):
msg = 'No {0.author.mention}, you do it'.format(message)
await message.channel.send(msg)
elif message.content.startswith('!tickers'):
cmd = message.content
cmd = cmd[9:]
print('tickers command ticker: ' + cmd)
try:
tickers = WebScrape.printTickers(cmd)
msg = ''
for tick in tickers:
msg = msg + tick + '\n'
except:
msg = 'Not a valid option\nLook at !listOptions'
await message.channel.send(msg)
elif message.content.startswith('!setOption'):
cmd = message.content
cmdParts = cmd.split()
WebScrape.setOption(cmdParts[1], cmdParts[2])
msg = '{0.author.mention} new option added '.format(message) + cmdParts[2]
await message.channel.send(msg)
elif message.content.startswith('!removeOption'):
cmd = message.content
cmdParts = cmd.split()
WebScrape.removeOption(cmdParts[1])
msg = '{0.author.mention} option was removed '.format(message) + cmdParts[1]
await message.channel.send(msg)
elif message.content.startswith('!listOptions'):
options = WebScrape.getOptions()
msg = ''
if options == 'There are no current options setup use !setOptions to set a new option':
msg = options
else:
for opt in options:
msg = msg + opt + '\n'
await message.channel.send(msg)
elif message.content.startswith('!stock'):
cmd = message.content
cmdParts = cmd.split()
GenerateGraph.makeGraph(cmdParts[1])
graphFile = File('stock_information.html')
await message.channel.send(file = graphFile)
elif message.content.startswith('!help'):
msg = 'Remember to seperate each part of the command with a space\n'
msg = msg + '!setOption <link to screener> <name of option (one word)>\n'
msg = msg + '!removeOption <name of option>\n'
msg = msg + '!listOptions\n'
msg = msg + '!tickers <name of option>\n'
msg = msg + '!stock <stock ticker>\n'
await message.channel.send(msg)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)