-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (87 loc) · 3.36 KB
/
main.py
File metadata and controls
105 lines (87 loc) · 3.36 KB
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
import discord
from discord.ext import commands
import os
bot = commands.Bot(command_prefix='!')
#Input your bot Token here.
token = "TokenTokenToken"
#Input the Discord ID's of the users you want to be able to use the !add and !delete commands.
userIDS = [ID1, ID2, ID3, ...]
if not (os.path.isfile('response.txt')):
f= open("response.txt","w+")
f.close()
@bot.event
async def on_ready():
print("Ready!")
@bot.event
async def on_message(message):
with open("response.txt","r") as f:
filedata = f.read()
try:
filedata = filedata.split("!$!")
except Exception as e:
print(e)
msgList = []
respList = []
for i in filedata:
if i !="":
msgList.append(i.split("~")[0].lower())
respList.append(i.split("~")[1])
if message.content.lower() in msgList:
response = respList[msgList.index(message.content.lower())]
await message.channel.send(response)
await bot.process_commands(message)
@bot.command()
async def add(ctx,*,arg):
if ctx.author.id in userIDS:
with open("response.txt","r") as f:
filedata = f.read()
try:
filedata = filedata.split("!$!")
except Exception as e:
print(e)
_message = arg.split("~")[0]
rsp =arg.split("~")[1]
print(f"New pair add request -> {_message} : {rsp}")
msgList = []
for i in filedata:
if i !="":
msgList.append(i.split("~")[0].lower())
if _message.lower() in msgList:
embed=discord.Embed(title="Couldn't Add", description=f"Message **\'{arg}\'** already exists!", color=0xff0000)
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="Message Pair Added!", description=f"Response message have been added!", color=0x00ff00)
embed.add_field(name="Message", value=_message, inline=True)
embed.add_field(name="Response", value=rsp, inline=True)
await ctx.send(embed=embed)
filedata.append(_message+"~"+rsp)
with open("response.txt","w") as f:
f.write("!$!".join(filedata))
@bot.command()
async def delete(ctx,*,arg):
if ctx.author.id in userIDS:
with open("response.txt","r") as f:
filedata = f.read()
try:
filedata = filedata.split("!$!")
except Exception as e:
print(e)
msgList = []
respList = []
for i in filedata:
if i !="":
msgList.append(i.split("~")[0].lower())
respList.append(i.split("~")[1].lower())
if arg.lower() in msgList:
indx = msgList.index(arg.lower())+1
filedata.pop(indx)
embed=discord.Embed(title="Message Pair Deleted!", description=f"Message for pair have been deleted!", color=0x00ff00)
embed.add_field(name="Message", value=arg, inline=True)
embed.add_field(name="Response", value=respList[msgList.index(arg.lower())], inline=True)
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="Couldn't Find", description=f"Message **\'{arg}\'** does not exists!", color=0xff0000)
await ctx.send(embed=embed)
with open("response.txt","w") as f:
f.write("!$!".join(filedata))
bot.run(token)