This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.py
175 lines (137 loc) · 4.93 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
# Enable Developer Mod in discord , go to appearances and on developer mod :)
import asyncio
import datetime
import json
import os
import random
from itertools import cycle
from threading import Thread
import discord
import motor.motor_asyncio
import nest_asyncio
import psutil
from discord.ext import commands, tasks
from discord.ext.commands import BucketType, cooldown
from discord.utils import get
from flask import Flask
from pymongo import MongoClient
import discord_pass
nest_asyncio.apply()
mongo_url = os.environ.get("MONGO_URL")
cluster = motor.motor_asyncio.AsyncIOMotorClient(mongo_url)
predb = cluster["discord"]["prefix"]
async def get_prefix(client, message):
stats = await predb.find_one({"guild": message.guild.id})
# server_prefix = stats["prefix"]
if stats is None:
updated = {"guild": message.guild.id, "prefix": "--"}
await predb.insert_one(updated)
extras = "--"
return commands.when_mentioned_or(extras)(client, message)
else:
extras = stats["prefix"]
return commands.when_mentioned_or(extras)(client, message)
client = commands.AutoShardedBot(
command_prefix=get_prefix, intents=discord.Intents.all()
)
client.remove_command("help")
status = cycle(["Leafy | Ping to know prefix", "Leafy | Ping to know prefix"])
unicode_list = ["\U0001f600", "\U0001f970", "\U0001f609", "\U0001f60a", "\U0001f971"]
@client.event
async def on_ready():
change_status.start()
print("Bot is ready")
@client.event
async def on_guild_join(guild):
updated = {"guild": guild.id, "prefix": "--"}
predb.insert_one(updated)
print("Joined a guild")
try:
#
embed = discord.Embed(
title="Hello!",
description="Thanks for adding me to your server! I hope you like me <:rainblob:796632292503977995>! I got a new family :)",
color=0xFF0000,
)
embed.add_field(
name="Use --help to know more about me",
value="To get started use `--help` or `--help setup` to setup few things",
)
if guild.system_channel:
await guild.system_channel.send(embed=embed)
else:
print("No system channel")
except:
raise
@tasks.loop(seconds=5)
async def change_status():
await client.change_presence(activity=discord.Game(next(status)))
@client.command(hidden=True)
@cooldown(1, 60, BucketType.user)
async def hello(ctx):
msg = await ctx.send(f"Hello {ctx.author.mention}")
await msg.add_reaction(f"{random.choice(unicode_list)}")
@client.command(description="Sends a password of given length")
@cooldown(1, 10, BucketType.user)
async def password(ctx, passlength=10):
passlength = int(passlength)
if passlength > 51:
embed = discord.Embed(
title="Invalid usage",
description="Your password cannot be so long",
color=0xFF000,
)
embed.set_image(
url="https://media1.tenor.com/images/7cb7b5cc74e9a63d11e474a3e135d617/tenor.gif"
)
await ctx.send(embed=embed)
elif passlength < 51:
passwor = discord_pass.secure_password_gen(passlength)
embed = discord.Embed(
title="Password Sent <:CheckMark:795884692024590367>",
description="Check your dm for password ",
color=0xFF000,
)
await ctx.send(embed=embed)
await ctx.send(f"{ctx.author.mention} Check your dm for the password! ")
await ctx.author.send(f"You password is \n `{passwor}`")
@client.command(hidden=True)
async def load(ctx, extension):
if ctx.author.id == 727365670395838626:
client.load_extension(f"cogs.{extension}")
await ctx.send("Done")
@client.command(hidden=True)
async def unload(ctx, extension):
if ctx.author.id == 727365670395838626:
client.unload_extension(f"cogs.{extension}")
await ctx.send("Done")
@client.command(hidden=True)
async def reload(ctx, extension):
if ctx.author.id == 727365670395838626:
client.unload_extension(f"cogs.{extension}")
client.load_extension(f"cogs.{extension}")
await ctx.send("Done")
@client.event
async def on_message(msg):
if (
msg.content == "<@791888515100573727>"
or msg.content == "<@!791888515100573727>"
):
stats = await predb.find_one({"guild": msg.guild.id})
if stats is None:
pref = "--"
else:
pref = stats["prefix"]
embed = discord.Embed(color=0xFF0000)
embed.set_author(
name=f"My prefix is `{pref}` and use `{pref}help` to see all commands",
icon_url=msg.author.avatar_url,
)
await msg.channel.send(embed=embed)
await client.process_commands(msg)
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
client.load_extension(f"cogs.{filename[:-3]}")
client.load_extension("jishaku")
token = os.environ.get("BOT_TOKEN")
client.run(f"{token}") # Here goes your token in ''