-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
125 lines (109 loc) · 5.48 KB
/
run.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
import discord
import requests
import re
from Plugins import roleAuth
from Plugins import botConf
from Plugins import fccid
from Plugins import hamCall
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
await client.change_presence(game=discord.Game(name='?help'))
@client.event
async def on_message(message):
if message.content.startswith('?help'):
#await client.purge_from(message.channel, limit=1, check=message.author)
#help_file = open("help.txt", "r")
#help_msg = help_file.read()
help_msg = botConf.grabHelp()
privateMessage = await client.start_private_message(message.author)
await client.send_message(privateMessage, help_msg)
if message.content.startswith('?updatehelp'):
if roleAuth.adminRole(message.author.id):
privateMessage = await client.start_private_message(message.author)
msg = message.content
stripped = re.sub('\?updatehelp', '', msg)
await client.send_typing(message.channel)
await client.send_message(privateMessage, "Thanks, here is a preview of your help file\r\n\r\n" + stripped + '\r\n\r\n\r\n')
await client.send_message(privateMessage, 'Type \'confirmed\' to save.')
if await client.wait_for_message(author=message.author, content='confirmed'):
botConf.updateHelp(stripped)
await client.send_typing(message.channel)
await client.send_message(privateMessage, 'updated')
# if message.content.startswith('!call'):
# if roleAuth.checkRole(client, message):
# await client.send_typing(message.channel)
# msg = message.content
# split = msg.split(' ')
# print(hamCall.callsign_start(split[1]))
# await client.send_message(message.channel, hamCall.callsign_start(split[1]))
if message.content.startswith('!id'):
if roleAuth.checkRole(client, message):
await client.send_typing(message.channel)
try:
msg = message.content
split = msg.split(' ')
id = split[1].upper()
pageRequest = requests.get("http://fccid.io/%s" % id)
if fccid.isValid(pageRequest) == True: ##check to see if the fcc id is valid
url1 = ('https://fccid.io/%s\\' % id)
url2 = ('https://gov.fccid.io/%s\\' % id)
title = fccid.manu(pageRequest, id)
freq = fccid.freq(pageRequest)
photos = fccid.internal(pageRequest)
power = fccid.power(pageRequest)
diagram = fccid.diagram(pageRequest)
schematics = fccid.schematics(pageRequest)
part = fccid.part(pageRequest)
assembled = "```" + title + "\r\n" + freq + "\r\n" + power + " " + part + "```" + "\r\n" + 'Details: ' + url1 + ' or ' + url2 + '\r\n' + photos + '\r\n' + diagram + '\r\n' + schematics
await client.send_message(message.channel, assembled)
else:
await client.send_message(message.channel, "Sorry that ID does not appear to be valid")
except:
await client.send_message(message.channel,
'Sorry, the website syntax must be weird on this one.\rTake your pick of links instead.\n\r\n' + 'FCCID: ' + url1 + '\r\n' + 'FCC.GOV: ' + url2)
print("Debug " + assembled)
else:
privateMessage = await client.start_private_message(message.author)
await client.send_message(privateMessage, 'Sorry You don\'t have the botaccess role')
if message.content.startswith('?myid'):
print(message.author.id)
if message.content.startswith('?getroles'):
if roleAuth.adminRole(message.author.id):
privateMessage = await client.start_private_message(message.author)
await client.send_message(privateMessage, botConf.grabAuthroles())
if message.content.startswith('?updateroles'):
if roleAuth.adminRole(message.author.id):
privateMessage = await client.start_private_message(message.author)
msg = message.content.lower()
split = msg.split(' ', 4)
try:
role1 = split[1]
except:
role1 = 'None'
try:
role2 = split[2]
except:
role2 = 'None'
try:
role3 = split[3]
except:
role3 = 'None'
try:
role4 = split[4]
except:
role4 = 'None'
await client.send_typing(message.channel)
await client.send_message(privateMessage, 'Below are the new roles, to save these roles now type: confirmed')
await client.send_message(privateMessage, 'Role1: ' + role1 + '\r\nRole2: ' + role2 + '\r\nRole3: ' + role3 + '\r\nRole4: ' + role4)
if await client.wait_for_message(author=message.author, content='confirmed'):
botConf.updateAuthroles(role1, role2, role3, role4)
await client.send_message(privateMessage, 'Authorized roles have been succesfully saved.')
else:
await client.send_message(privateMessage, 'Authorized roles have NOT been saved.')
client.run(botConf.grabKey())
#client.run(botConf.devKey())