-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
200 lines (146 loc) · 5.22 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
193
194
195
196
197
198
199
200
import discord
import sys
import logging
from typing import Mapping
import typing
import datetime
import asyncio
import random
import json
import os
from discord.ext import commands
import cogs._json
from imports import StaticEmoji, animatedEmojis, statusEmojis
# cwd = Path(__file__).parents[0]
# wd = str(cwd)
# print(f"{cwd}\n-----")
# Define emojis for file
tick = StaticEmoji.tick
online = statusEmojis.anim_online
no = StaticEmoji.no
animatedDnd = statusEmojis.anim_dnd
async def get_prefix(client, message):
if message.guild is None:
prefixes = ["av!", "AV!", "!av "]
elif message.author.id == 701727675311587358:
#prefixes = ["av!", "Av!", "!av", '']
data = cogs._json.read_json("mypre")
prefixes=data["prefixes"]
elif message.author.id == 736482645931720765:
data = cogs._json.read_json("mypre")
prefixes=data["prefixes"]
else:
prefixes = ["av!", "Av!", "AV!", "!av "]
return commands.when_mentioned_or(*prefixes)(client, message)
# Defining a few things
# secret_file = json.load(open(cwd+'/bot_config/.env'))
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=get_prefix, case_insensitive=True, owner_ids={ 736482645931720765, 701727675311587358}, intents=discord.Intents.all())
bot.remove_command('help')
logging.basicConfig(level=logging.INFO)
bot.blacklisted_users = []
bot.launch_time = datetime.datetime.utcnow()
# bot.cwd = cwd
def callable_pref(bot, message):
prefix_return = ["av!"]
return commands.when_mentioned_or(bot.prefixes[message.guild.id])(bot, message)
bot.version = '2.4.4'
@bot.event
async def on_ready():
print(f"Logged in As {bot.user}.")
await bot.change_presence(status=discord.Status.idle,
activity=discord.Activity(type=discord.ActivityType.listening, name="av!help"))
# chan = await bot.fetch_channel(972083876811931669)
# msg = await chan.fetch_message(972084220304457768)
# try:
# data = cogs._json.read_json("restart")
# chan1 = data["channelId"]
# msg1 = data["messageId"]
# chan2 = await bot.fetch_channel(chan1)
# msg2 = await chan2.fetch_message(msg1)
# print("\n")
# await msg2.edit(content='Restarted!')
# data["channelId"] = ""
# data["messageId"] = ""
# cogs._json.write_json(data, "restart")
# except Exception:
# pass
# await msg.edit(content=f"""
# **{online} Online**
# ------------------------------
# {tick} Cogs: Loaded
# ------------------------------
# {tick} Commands: Fully Functional
# ------------------------------
# {tick} Maintenance Mode: False
# ------------------------------
# {tick} Errors: 0""")
@bot.event
async def on_message(message):
# Ignore messages sent by yourself
if message.author.id == bot.user.id:
return
# A way to blacklist users from the bot by not processing commands if the author is in the blacklisted_users list
data = cogs._json.read_json("blacklist")
if message.author.id in data["blacklistedUsers"]:
return
if message.guild.id == 801671810730426418:
await message.channel.send("Guild is blacklisted for violating ToS.")
return
# Whenever the bot is tagged, respond with its prefix #in message.content
if message.content.startswith(f"<@!{bot.user.id}>"):
data = cogs._json.read_json('prefixes')
if str(message.guild.id) in data:
prefix = data[str(message.guild.id)]
else:
prefix = 'av!'
await message.channel.send(f"My prefix here is `{prefix}`")
await bot.process_commands(message)
bot.load_extension("jishaku")
os.environ["JISHAKU_NO_UNDERSCORE"] = "True"
os.environ["JISHAKU_NO_DM_TRACEBACK"] = "True"
os.environ["JISHAKU_HIDE"] = "True"
@bot.event
async def on_message_edit(before, after):
try:
await bot.process_commands(after)
except:
return
"""deletelog={}
@bot.event
async def on_message_delete(message):
if message.id in deletelog:
dellog = deletelog[message.id]
await dellog.delete()
del deletelog[message.id]"""
@bot.command(hidden=True, aliases=['rs'])
@commands.is_owner()
async def restart(ctx):
chan = await bot.fetch_channel(972083876811931669)
msg = await chan.fetch_message(972084220304457768)
message = await ctx.reply("Restarting...")
data = cogs._json.read_json("restart")
data["channelId"] = ctx.channel.id
data["messageId"] = message.id
cogs._json.write_json(data, "restart")
await msg.edit(content=f"""
**{animatedDnd} Restarting...**
------------------------------
{no} Cogs: Unloaded
------------------------------
{no} Commands: Error
------------------------------
{no} Maintenance Mode: Failed
------------------------------
{tick} Errors: 0""")
await bot.close()
python = sys.executable
os.execl(python, python, *sys.argv)
if __name__ == '__main__':
# When running this file, if it is the 'main' file
# I.E its not being imported from another python file run this
for filename in os.listdir('./cogs/'):
if filename.endswith(".py") and not filename.startswith("_"):
bot.load_extension(f"cogs.{filename[:-3]}")
token = os.environ.get("token")
bot.run(token)