This repository was archived by the owner on Jul 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbot.py
More file actions
220 lines (185 loc) · 7.33 KB
/
Copy pathbot.py
File metadata and controls
220 lines (185 loc) · 7.33 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
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
#The Iron Fleet's Iron Justice Bot
#Primary intention: Supporting the Iron Fleet's Discord server.
#Secondary intention: gimicks like the profile System
#Author Maxe aka. Cradac
#Version: 3.2.0 rewrite
import discord
from discord.ext import commands
import sys, traceback, json
from datetime import datetime
from utils import utils
_version = '3.2.0'
print(sys.version)
print(discord.__version__)
print('bot version: {}'.format(_version))
intents = discord.Intents.default()
intents.members = True
intents.bans = False
intents.integrations = False
intents.webhooks = False
intents.invites = False
intents.typing = False
Client = discord.Client()
client = commands.Bot(command_prefix = ['?'], case_insensitive=True, intents=intents, help_command=None, description=f'This is the Iron Fleet\'s own bot THE IRON JUSTICE V{_version} rewrite. For questions please contact Cradac | Max#2614.\n#beMoreIron')
if len(sys.argv) == 1:
with open('token.json') as f:
c = json.load(f)
bot_token = c.get('token')
else:
bot_token = sys.argv[1]
#sys.stdout = open(datetime.now().strftime('logs/discord_log_%Y_%m_%d_%H_%M_%S.log'), 'w+')
extensions = ['auto_voice', 'ironfleet', 'lfc', 'misc', 'profile', 'settings', 'welcome']
##########################################################################################################################################
@client.event
async def on_ready():
print('Bot is ready!')
game = discord.Game('the Iron Price | ?help')
await client.change_presence(status=discord.Status.online, activity=game)
print('Logged in as: ' + client.user.name)
print('Bot ID: ' + str(client.user.id))
print (f'Connected to {str(len(client.guilds))} servers.')
print('------')
@client.event
async def on_message(message):
if type(message.channel) is discord.DMChannel:
return
log_channel = discord.utils.get(message.guild.channels, name="message-log")
if not log_channel :
await client.process_commands(message)
return
if not message.author.bot:
jump_to_message = f'[Jump](https://discordapp.com/channels/{message.guild.id}/{message.channel.id}/{message.id})'
embed = utils.createEmbed(description=f'in {message.channel.mention}:\n{message.content}\n{jump_to_message}', colour='iron', author=message.author)
embed.set_footer(text=message.author.id)
if len(message.attachments) > 0:
embed.set_image(url=message.attachments[0].url)
await log_channel.send(embed=embed)
await client.process_commands(message)
@client.event
async def on_message_edit(before, after):
await client.process_commands(after)
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CheckFailure) or isinstance(error, commands.CommandNotFound):
pass
elif isinstance(error, commands.BadArgument):
embed = utils.createEmbed(
description=f'Error: There was an error with the command arguments.\n\nUsage:\n`{ctx.command.usage}`',
colour='error',
author=ctx.author)
await ctx.send(embed=embed)
elif isinstance(error, commands.MissingRequiredArgument):
embed = utils.createEmbed(
description=f'Error: Your are missing an argument.\n\nUsage:\n`{ctx.command.usage}`',
colour='error',
author=ctx.author)
await ctx.send(embed=embed)
'''
else:
try:
embed = utils.createEmbed(
title='An error eccured',
description=f'\
**{type(error)}**\n\
```{error}```\n\n\
[Jump](https://discordapp.com/channels/{ctx.guild.id}/{ctx.channel.id}/{ctx.message.id})',
author=ctx.author,
colour='error'
)
embed.set_footer(text=ctx.guild.name, icon_url=ctx.guild.icon_url_as(format='png', size=128))
app = await client.application_info()
await app.owner.send(embed=embed)
raise error
except Exception as error:
tb = traceback.format_exc()
print(error, tb)'''
##########################################################################################################################################
@client.command(hidden=True, brief='Pong!')
async def ping(ctx):
await ctx.send('Pong! `({} ms)`'.format(round(client.latency, 2)))
@client.command(hidden=True, brief='Version Info')
async def version(ctx):
await ctx.send(f'\
bot version: `{_version}`\n\
discord.py version: `{discord.__version__}`\n\
system info: `{sys.version}`')
@client.command(brief='Help Command.')
async def help(ctx, *, name: str = None):
if name:
embed = utils.createEmbed(colour='iron')
command = client.get_command(name=name)
cog = client.get_cog(name=name)
if cog:
embed.title = f'__Module: {cog.qualified_name}__'
txt = ''
for command in cog.get_commands():
txt += f'{client.command_prefix[0]}{command.name} - {command.brief}\n'
embed.add_field(name='Commands', value=txt, inline=False)
elif command:
embed.title = f'__Command: {client.command_prefix[0]}{command.qualified_name}__'
embed.add_field(name='Description', value=command.description, inline=False)
if isinstance(command, discord.ext.commands.Group):
embed.add_field(name='Subcommands', value='\n'.join(f'`{c.name}`' for c in command.commands), inline=False)
embed.add_field(name='Usage', value=command.usage, inline=False)
if len(command.aliases) > 0:
embed.add_field(name='Aliases', value=', '.join(f'`{a}`' for a in command.aliases), inline=False)
embed.set_footer(text=f'Module: {command.cog_name}')
else:
embed = utils.createEmbed(colour='error', description='Error: Command or Cog not found.', author=ctx.author)
else:
embed = utils.createEmbed(title='__Commands__', description='For a documentation of all commands go [here](https://gist.github.com/Cradac/4544f0cbe9456a637c0d3a85061bda78).', colour='iron')
for name, cog in client.cogs.items():
commands = cog.get_commands()
if len(commands) > 0:
txt = ''
for command in commands:
if command.hidden:
continue
txt += f'{client.command_prefix[0]}{command.name} - {command.brief}\n'
if txt != '':
embed.add_field(name=cog.qualified_name, value=txt, inline=False)
else:
continue
await ctx.send(embed=embed)
##########################################################################################################################################
@commands.is_owner()
@client.command(hidden=True)
async def kill(ctx):
print('Bot shutting down...')
await client.close()
@commands.is_owner()
@client.command(hidden=True)
async def load(ctx, extension_name: str):
try:
extension_name = f'cogs.{extension_name}'
client.load_extension(extension_name)
except (AttributeError, ImportError) as e:
print(f'{type(e).__name__}: {e}')
return
print(f'`{extension_name}` loaded.')
@commands.is_owner()
@client.command(hidden=True)
async def unload(ctx, extension_name: str):
extension_name = f'cogs.{extension_name}'
client.unload_extension(extension_name)
print(f'`{extension_name}` unloaded.')
@commands.is_owner()
@client.command(hidden=True)
async def reload(ctx, extension_name: str):
try:
extension_name = f'cogs.{extension_name}'
client.unload_extension(extension_name)
client.load_extension(extension_name)
except (AttributeError, ImportError) as e:
print(f'{type(e).__name__}: {e}')
return
print(f'`{extension_name}` reloaded.')
if __name__ == "__main__":
for extension in extensions:
try:
client.load_extension(f'cogs.{extension}')
print(f'Loaded Extension {extension} on boot-up.')
except Exception as e:
exc = f'{type(e).__name__}: {e}'
print(f'Failed to load extension {extension}\n{exc}')
client.run(bot_token)