-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainbot.py
239 lines (164 loc) · 6.63 KB
/
mainbot.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import pkg_resources
__requires__= 'discord==1.7.3'
import pkg_resources
pkg_resources.require("discord==1.7.3")
from discord.ext import commands
import discord,asyncio
#client = discord.Client(intents=discord.Intents.all())
bot = commands.Bot(intents=discord.Intents.all(),command_prefix="!", case_insensitive=True)
global vc,stor
print("Initiating Bot")
with open("interact.txt","w+",encoding="utf8") as interact:
with open("start.txt","r+",encoding="utf8") as start:
x=start.read()
interact.write(x)
with open("interact.txt","r+",encoding="utf8") as interact:
z=interact.read()
stor={"interact":z}
with open("config.txt","r+",encoding="utf8") as interact:
z2=interact.read()
stor={"config":z2}
#functions
def locate(file,item,no): #file is which file to check,item is parameter, no is number of parameters
para=stor[file]
b=para.find(item+"=")+len(item)+1
c=0
for i in range(0,no):
if i==0:
a=(para.find("|;",para.find(item+"=")))
elif i>0:
a=(para.find("|;",b))
if i==no-1:
c=para[b:a]
b=a+2
return c
def replacing(file,item,no,word): #file is which file to check,item is parameter, no is number of parameters,word is what is goning to replace the og
para=stor[file]
b=para.find(item+"=")+len(item)+1
for i in range(0,no):
if i==0:
a=(para.find("|;",para.find(item+"=")))
elif i>0:
a=(para.find("|;",b))
if i==no-1:
stor[file]=stor[file][:b]+stor[file][b:a].replace(para[b:a],word)+stor[file][a:]
if file=="config":
with open("config.txt","w+",encoding="utf8") as config:
config.write(stor[file])
if file=="interact":
with open("interact.txt","w+",encoding="utf8") as config:
config.write(stor[file])
b=a+2
if no==-1:
a=len(stor[file][:b])+stor[file][b:].index("|;;")
stor[file]=stor[file][:b]+stor[file][b:a].replace(para[b:a],word)+stor[file][a:]
if file=="config":
with open("config.txt","w+",encoding="utf8") as config:
config.write(stor[file])
pass
#client.run(token)
textChannelID=int(locate("config","TextChannel",1))
voiceChannelID=int(locate("config","VoiceChannel",1))
token=(locate("config","Token",1))
#use ctx for commands to call with !example, button commands dont use
@bot.command(pass_context=True)
async def aaa(ctx):
print(discord.TextChannel._get_channel)
print("DOne")
@bot.command(pass_context=True)
async def join(ctx):
print("A")
@bot.command()
async def getmsg(ctx, channel: discord.TextChannel, member: discord.Member):
msg = discord.utils.get(await bot.history(limit=100).flatten(), author=member)
# this gets the most recent message from a specified member in the past 100 messages
@bot.command(pass_context=True)
async def leave(ctx):
global vc
await vc.disconnect()
#@bot.command(pass_context=True)
async def joiner():
global vc
#voice channel
channel1 =bot.get_channel(voiceChannelID)
#text channel
channel2 = bot.get_channel(textChannelID)
try:
vc= await channel1.connect()
except:
await channel2.send("Already connected to a voice channel.")
async def messageSender():
await textChannel.send()
#@bot.command(pass_context=True)
async def leaver():
global vc
channel2 = bot.get_channel(textChannelID)
try:
await vc.disconnect()
except:
await channel2.send("name 'vc' is not defined.")
#@bot.command(pass_context=True)
async def player(file):
global vc
try:
vc.play(discord.FFmpegPCMAudio('sound_files/'+file))
except:
pass
@bot.command(pass_context=True)
async def pauser():
global vc
vc.pause()
@bot.command(pass_context=True)
async def unpauser():
global vc
vc.resume()
@bot.command(pass_context=True)
async def search_submissions():
global vc,stor
while(True):
await bot.wait_until_ready()
with open("interact.txt","r+",encoding="utf8") as interact:
z=interact.read()
stor={"interact":z}
channel1 = bot.get_channel(textChannelID)
if (locate("interact","status",1)=="starting"):
await channel1.send("client start")
print("Bot Online")
replacing("interact","status",1,"offline0")
if ((locate("interact","status",1)=="online1")):
bot.loop.create_task(joiner())
print("Started connection to Discord")
replacing("interact","status",1,"online0")
elif ((locate("interact","status",1)=="offline1")):
await channel1.send("leaving")
print("Discord Disconnected")
bot.loop.create_task(leaver())
replacing("interact","status",1,"offline0")
try:
if vc.is_connected():
replacing("interact","connected",1,"True")
elif vc.is_connected()!=True:
replacing("interact","connected",1,"False")
if vc.is_playing():
replacing("interact","playstate",1,"True")
elif not vc.is_playing():
replacing("interact","playstate",1,"False")
except:
pass
if locate("interact","player",1)=="play" and locate("interact","player",4)=="1":
if locate("interact","playstate",1)=="False":
bot.loop.create_task(player(locate("interact","player",2)))
replacing("interact","player",4,"0")
elif locate("interact","playstate",1)=="True":
await channel1.send("Audio already playing")
if locate("interact","player",1)=="pause" and locate("interact","player",4)=="1":
bot.loop.create_task(pauser())
replacing("interact","player",4,"0")
elif locate("interact","player",1)=="unpause" and locate("interact","player",4)=="1":
bot.loop.create_task(unpauser())
replacing("interact","player",4,"0")
await asyncio.sleep(0.03)
bot.loop.create_task(search_submissions())
#bot.add_command(check)
#client.run(token)
bot.run(token)