-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
209 lines (174 loc) · 6.73 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
201
202
203
204
205
206
207
208
209
# coding=utf-8
import settings
import subprocess
import datetime
import os
import platform
import logging
import asyncio
import sys
import traceback
import nextcord
from nextcord.ext import commands, tasks
from datetime import date, timedelta
from itertools import cycle
logger = logging.getLogger("discord")
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename="logs/botlog.log", encoding="utf-8", mode="w")
handler.setFormatter(
logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")
)
logger.addHandler(handler)
intent = nextcord.Intents.default()
intent.members = True
PYTHON_VERSION = platform.python_version()
OS = platform.system()
status = cycle(
[
f" S | {settings.COMMAND_PREFIX}help ",
f" Sm | {settings.COMMAND_PREFIX}help ",
f" Smi | {settings.COMMAND_PREFIX}help ",
f" Smil | {settings.COMMAND_PREFIX}help ",
f" Smile | {settings.COMMAND_PREFIX}help ",
f" Smilew | {settings.COMMAND_PREFIX}help ",
f" Smilewi | {settings.COMMAND_PREFIX}help ",
f" Smilewin| {settings.COMMAND_PREFIX}help ",
f" Smilewin| {settings.COMMAND_PREFIX}help ",
]
)
ASCII_ART = """
____ _ _ _
/ ___| _ __ ___ (_) | _____ _(_)_ __
\___ \| '_ ` _ \| | |/ _ \ \ /\ / / | '_ \
__) | | | | | | | | __/\ V V /| | | | |
|____/|_| |_| |_|_|_|\___| \_/\_/ |_|_| |_|
REACT#1120
"""
bot = commands.AutoShardedBot(
command_prefix=settings.COMMAND_PREFIX,
case_insensitive=True,
help_command=None,
intents=intent,
strip_after_prefix=True,
)
start_time = datetime.datetime.utcnow()
async def clearcmd():
subprocess.call("cls" if os.name == "nt" else "clear", shell=True)
@tasks.loop(seconds=5)
async def change_status():
await bot.wait_until_ready()
await bot.change_presence(
status=nextcord.Status.idle,
activity=nextcord.Streaming(
name=next(status), url="https://www.twitch.tv/smilewinbot"
),
)
@tasks.loop(seconds=120)
async def serverstat():
await bot.wait_until_ready()
results = settings.collectionstatus.find({"status_system": "YES"})
for data in await results.to_list(length=10000):
if data["guild_id"] in bot.guilds:
guild = bot.get_guild(data["guild_id"])
print(data["guild_id"])
memberonly = len([member for member in guild.members if not member.bot])
botonly = int(guild.member_count) - int(memberonly)
total_member_channel = bot.get_channel(data["status_total_id"])
member_channel = bot.get_channel(data["status_members_id"])
bot_channel = bot.get_channel(data["status_bots_id"])
if total_member_channel:
await total_member_channel.edit(name=f"︱👥 Total : {guild.member_count}")
if member_channel:
await member_channel.edit(name=f"︱👥 Members : {memberonly}")
if bot_channel:
await bot_channel.edit(name=f"︱👥 Bots : {botonly}")
else:
pass
async def checkMongo():
try:
await settings.client.admin.command("ismaster")
print("Successfully connected to mongodb")
except Exception:
print("Unable to connect to mongodb")
def loadcogs():
for filename in os.listdir("cogs"):
if filename.endswith(".py") and not filename.startswith("_"):
try:
bot.load_extension(f"cogs.{filename[:-3]}")
print(f"Successfully loaded {filename}")
except Exception as e:
print(f"Failed to load {filename}")
print(e)
traceback.print_exc()
def reloadallcogs():
for filename in os.listdir("cogs"):
if filename.endswith(".py") and not filename.startswith("_"):
try:
bot.reload_extension(f"cogs.{filename[:-3]}")
print(f"Successfully reloaded {filename}")
except Exception as e:
print(f"Failed to reloaded {filename}")
print(e)
traceback.print_exc()
@bot.event
async def on_ready():
loadcogs()
await settings.collectionmusic.delete_many({})
try:
change_status.start()
serverstat.start()
except RuntimeError:
pass
await print_ascii_art()
try:
channel = bot.get_channel(int(settings.logchannel))
embed = nextcord.Embed(title=f"Bot is online", colour=0x56FF2D)
await channel.send(embed=embed)
except Exception as e:
print(e)
pass
async def print_ascii_art():
name_space = (25 - (len(str(bot.user)))) * (" ")
server = str(len(bot.guilds))
server_space = (27 - int(len(server))) * (" ")
user = str(len(bot.users))
user_space = (29 - int(len(user))) * (" ")
print(f"{ASCII_ART}")
print(
f" ╔══════════════════════════════════════╗"
)
print(f" ║ BOT NAME : {bot.user}{name_space}║")
print(f" ║ BOT ID : {bot.user.id} ║")
print(
f" ║ BOT STATUS : ONLINE ║"
)
print(f" ║ SERVER : {server}{server_space}║")
print(f" ║ USER : {user}{user_space}║")
print(
f" ║ ║"
)
print(
f" ╚══════════════════════════════════════╝\n"
)
@bot.command(aliases=["reload"])
@commands.is_owner()
async def reloadcogs(ctx: commands.Context):
reloadallcogs()
print("Reloaded all cogs!")
await ctx.send("Reloaded all cogs successfully!")
@bot.command()
async def cleancmd(ctx: commands.Context):
await clearcmd()
await checkMongo()
await print_ascii_art()
await ctx.send("Cmd cleared")
@bot.event
async def on_connect():
print("Connected to discord API")
def main():
try:
bot.run(settings.TOKEN, reconnect=True)
except Exception as e:
print(e)
if __name__ == "__main__":
main()