Added custom prefix & info

This commit is contained in:
Nemika
2021-03-08 13:53:06 +02:00
parent b34c24dfc4
commit 503e4e7871
9 changed files with 131 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
import discord, io, traceback, json, os
import discord, io, traceback, json, os, asyncio
from colorama import Fore, Style, init
from dateparser import parse
init(autoreset=True)
@@ -23,10 +24,11 @@ class Bumps(commands.Cog):
async def bump(self, ctx):
server = Servers(ctx.guild.id)
guild = ctx.guild
prefix = Servers(guild.id).getPrefix() if Servers(guild.id).hasPrefix else self.config["prefix"]
if not server.get():
ctx.command.reset_cooldown(ctx)
return await ctx.send(embed=Embeds(f"You must setup this server first! Use `{self.config['prefix']}setup` to do so!"))
return await ctx.send(embed=Embeds(f"You must setup this server first! Use `{prefix}setup` to do so!").error())
servers = Servers().get_all()
@@ -89,12 +91,22 @@ class Bumps(commands.Cog):
#os.remove("cache_data.json")
return await ctx.send(embed=discord.Embed(
done_message = await ctx.send(embed=discord.Embed(
title="⏫ Server Bumped",
description=f"Your server was bumped to `{success+fail}` servers!\n✅ There were `{success}` successful bumps!\n❎ There were `{fail}` failed ones, they got booted from the Database!",
color=discord.Color.green()
)
.set_footer(text=f"Powered by • {self.config['bot_name']}"))
if settings["show_motd"]:
await asyncio.sleep(settings["show_motd_wait"])
return await done_message.edit(embed=discord.Embed(
title="🗞️ Message Of The Day 🗞️",
description=Data("motd").read(),
color=discord.Color.green()
))
else:
return
def setup(bot):
bot.add_cog(Bumps(bot))

38
cogs/info.py Normal file
View File

@@ -0,0 +1,38 @@
import discord
from core.database import Servers
from core.files import Data
commands = discord.ext.commands
class Info(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.config = Data("config").yaml_read()
@commands.guild_only()
@commands.command(aliases=['about'])
async def info(self, ctx):
return await ctx.send(embed=discord.Embed(
title=f"{self.config['bot_name']} | Information",
color=discord.Color.blurple()
)
.add_field(name="Version", value=self.config['version'])
.add_field(name="Library", value=f"Discord.py v{discord.__version__}")
.add_field(name="Latency", value=f"{round(self.bot.latency*1000)}ms")
.add_field(name="Servers", value=len(self.bot.guilds))
.add_field(name="Active Servers", value=len([i for i in Servers().get_all()]))
.add_field(name="Open Source", value="[View](https://github.com/Nemika-Haj/BytesBump)") # DO NOT REMOVE
.set_footer(text="Made by • " + ', '.join([str((await self.bot.fetch_user(i))) for i in self.config['managers']])))
@commands.guild_only()
@commands.command(aliases=['support'])
async def help(self, ctx):
return await ctx.send(embed=discord.Embed(
title=f"{self.config['bot_name']} | Help",
description=Data("help").read(),
color=discord.Color.blurple()
))
def setup(bot):
bot.add_cog(Info(bot))

37
cogs/prefix.py Normal file
View File

@@ -0,0 +1,37 @@
import discord
from core.database import Servers
from core.files import Data
from core import embeds
commands = discord.ext.commands
def getPrefix(bot, message):
prefix = [Data('config').yaml_read()['prefix']]
if message.guild:
server = Servers(message.guild.id)
prefix = [server.getPrefix()]
return commands.when_mentioned_or(*prefix)(bot, message)
class SetPrefix(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.guild_only()
@commands.has_permissions(manage_guild=True)
@commands.command()
async def setprefix(self, ctx, *, prefix=None):
server = Servers(ctx.guild.id)
if not prefix or prefix == "p!":
if server.hasPrefix: server.deletePrefix
return await ctx.send(embed=embeds.Embeds(f"The prefix was reset to default! `({Data('config').yaml_read()['prefix']})`").success())
server.setPrefix(prefix)
return await ctx.send(embed=embeds.Embeds(f"The prefix was set to `{prefix}`!").success())
@commands.Cog.listener()
async def on_guild_remove(self, guild):
server = Servers(guild.id)
if server.hasPrefix: server.deletePrefix
def setup(bot):
bot.add_cog(SetPrefix(bot))

View File

@@ -13,15 +13,20 @@ class BumpSetup(commands.Cog):
global setting_up
setting_up = []
@commands.Cog.listener('on_guild_remove')
async def remove_guild(self, guild):
Servers(guild.id).delete()
@commands.guild_only()
@commands.has_permissions(manage_guild=True)
@commands.check(lambda ctx: ctx.guild not in setting_up)
@commands.command()
async def setup(self, ctx):
guild = ctx.guild
prefix = Servers(guild.id).getPrefix() if Servers(guild.id).hasPrefix else self.config["prefix"]
if Servers(guild.id).get():
return await ctx.send(embed=Embeds(f"This server was already setup! Use `{self.config['prefix']}delete` to initialize another setup!").error())
return await ctx.send(embed=Embeds(f"This server was already setup! Use `{prefix}delete` to initialize another setup!").error())
embed = discord.Embed(
title="🔄 Setting Up...",

View File

@@ -7,6 +7,7 @@ class Servers:
def __init__(self, server=None):
self.server = server
self.col = client["BytesBump"]["servers"]
self.prefixes = client["BytesBump"]["prefixes"]
def get(self):
return self.col.find_one({"_id":self.server})
@@ -43,4 +44,26 @@ class Servers:
self.col.delete_one({'_id': self.server})
else:
self.col.delete_one(checks)
"""
Prefix management
"""
@property
def hasPrefix(self):
r = self.prefixes.find_one({'_id':self.server})
if r: return True
return False
@property
def deletePrefix(self):
self.prefixes.delete_one({'_id':self.server})
def setPrefix(self, prefix):
if self.hasPrefix: self.prefixes.update_one({'_id':self.server}, {'$set':{'prefix':prefix}})
else: self.prefixes.insert_one({'_id':self.server, 'prefix':prefix})
def getPrefix(self):
prefix = self.prefixes.find_one({'_id':self.server})
if prefix: return prefix["prefix"]
else: return Data("config").yaml_read()["prefix"]

1
data/help.txt Normal file
View File

@@ -0,0 +1 @@
This text will show up on the `help` command!

2
data/motd.txt Normal file
View File

@@ -0,0 +1,2 @@
This is a Message of the Day!
This will appear after the bump message IF "show_motd" is set to true in settings.json!

View File

@@ -1,3 +1,7 @@
{
"cooldown": 30
"cooldown": 3600,
"show_motd": false,
"show_motd_wait": 10,
"enable_serverlist": false,
"serverlist_url": "https://localhost:5000/"
}

View File

@@ -7,6 +7,8 @@ from core import checks
from colorama import init, Style, Fore
from cogs.prefix import getPrefix
from discord.ext import commands
init(autoreset=True)
@@ -15,7 +17,7 @@ config = Data("config").yaml_read()
intents = discord.Intents.default(); intents.members = True
bot = commands.Bot(command_prefix=config["prefix"], case_insensitive=True, help_command=None, intents=intents)
bot = commands.Bot(command_prefix=getPrefix, case_insensitive=True, help_command=None, intents=intents)
@bot.event
async def on_ready():