-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
192 lines (163 loc) · 5.71 KB
/
main.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
# imports
import traceback
from asyncio import sleep
import aiohttp
# Files
from discord import Embed, Color, Game, Forbidden, Message, Permissions
from discord.ext.commands import Bot, Context, has_permissions, Converter, BadArgument, CommandNotFound, \
MissingPermissions
from discord.utils import oauth_url
from config import config
class MyClient(Bot):
# noinspection PyMethodMayBeStatic
async def on_ready(self):
print("Login successful")
print("A list of all servers where the bot is on:")
# List of all Servers the Bot is
insguilds = 0
for guild in client.guilds:
print("%s - %s" % (guild.name, guild.id))
insguilds = insguilds + 1
print("Guilds: " + str(insguilds))
# Game Presence
game = Game(name=config.prefix + "help")
await client.change_presence(activity=game)
# noinspection PyMethodMayBeStatic
async def on_guild_join(self, guild):
headers = {
'Authorization': config.dbo_token}
data = {'server_count': len(client.guilds)}
api_url = 'https://discordbots.org/api/bots/384757717346025472/stats'
async with aiohttp.ClientSession() as session:
await session.post(api_url, data=data, headers=headers)
# noinspection PyMethodMayBeStatic
async def on_guild_remove(self, guild):
headers = {
'Authorization': config.dbo_token}
data = {'server_count': len(client.guilds)}
api_url = 'https://discordbots.org/api/bots/384757717346025472/stats'
async with aiohttp.ClientSession() as session:
await session.post(api_url, data=data, headers=headers)
# Log in to Bot
client = MyClient(command_prefix=config.prefix)
client.remove_command('help')
@client.command()
async def help(ctx: Context):
try:
await ctx.author.send(embed=Embed(
description=f"""
***Support***
**Prefix:**
{ctx.prefix}[command]
**Check if the bot is online**
{ctx.prefix}ping
shows that the bot is online and reads the messages
**delete messages**
{ctx.prefix}clear [ammount]
Deletes the specified number of messages
**Create a message**
{ctx.prefix}send color text
**with images**
{ctx.prefix}header color http://image.link your text
**Bot Info**
{ctx.prefix}info
-----------
Formatting of the message: *https://thebotdev.de/Markdown.html*
"""))
except Forbidden:
return await ctx.send(content="Error! i couldn't send you the message per DM")
await ctx.send(content="I sent you a private message with all the orders!")
@client.command()
@has_permissions(administrator=True)
async def clear(ctx: Context, amount: int = 1):
async for message in ctx.channel.history(limit=amount):
try:
await message.delete()
except Forbidden:
return await ctx.send(
embed=Embed(
color=Color.red(),
description="OH it looks like that i do not have the permissions to delete messages here. I am "
"sorry!"))
@client.command()
async def ping(ctx: Context):
await ctx.send(content="Pong!")
@client.command()
async def info(ctx: Context):
await ctx.send(
embed=Embed(
color=Color.purple(),
description=f"""
**Bot by:** *BaseChip*
**Project:** *TheBotDev*
**Support:** *[BaseChips support server](https://discord.gg/HD7x2vx)*
**Bot Invite:** *[INVITE BaseChips Bot]({oauth_url(client.user.id, Permissions(67577856))})*
*This is a fork from GitHub from the Bot from BaseChip*"""))
class ColorConverter(Converter):
async def convert(self, ctx: Context, argument: str):
try:
return getattr(Color, argument.lower())()
except (TypeError, AttributeError):
pass
try:
return Color(int(argument[1:], 16))
except (TypeError, ValueError):
raise BadArgument('Use a hex code or a color name from the supported colors')
@client.command(aliases=['image'])
@has_permissions(administrator=True)
async def header(ctx: Context, color: ColorConverter, link, *, text):
await ctx.send(
embed=Embed(
color=color,
description=text,
).set_thumbnail(url=link)
)
@client.command(aliases=['message'])
@has_permissions(administrator=True)
async def send(ctx: Context, color: ColorConverter, *, text):
await ctx.send(
embed=Embed(
color=color,
description=text,
)
)
async def on_command_error(ctx: Context, exc: BaseException):
print('command error')
mes: Message
if isinstance(exc, CommandNotFound):
mes = await ctx.send(
embed=Embed(
description=f"Command not found. See `{ctx.prefix}help`",
color=Color.red(),
)
)
elif isinstance(exc, BadArgument):
mes = await ctx.send(
embed=Embed(
description=exc.args[0],
color=Color.red()))
elif isinstance(exc, MissingPermissions):
mes = await ctx.send(
embed=Embed(
description="You are missing permissions.",
color=Color.red()
)
)
else:
mes = await ctx.send(
embed=Embed(
description=f"An exception occurred during the processing of this command. I might be missing "
f"permissions here, if not, join our support guild(`{ctx.prefix}info`) ",
color=Color.red()
)
)
try:
raise exc
except:
traceback.print_exc()
if mes:
await sleep(10)
await mes.delete()
client.on_command_error = on_command_error
if __name__ == '__main__':
client.run(config.token)