Skip to content

Commit

Permalink
more fuckery
Browse files Browse the repository at this point in the history
  • Loading branch information
fixator10 committed Aug 25, 2020
1 parent 22e3037 commit 3e0780a
Show file tree
Hide file tree
Showing 19 changed files with 723 additions and 648 deletions.
4 changes: 4 additions & 0 deletions leveler/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ async def _process_exp(self, message, userinfo, exp: int):
async def _give_chat_credit(self, user, server):
raise NotImplementedError

@abstractmethod
async def _valid_image_url(self, url):
raise NotImplementedError


class CompositeMetaClass(type(commands.Cog), type(ABC)):
"""
Expand Down
11 changes: 4 additions & 7 deletions leveler/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from ..abc import CompositeMetaClass
from .profiles import Profiles
from .database import DataBase
from .top import Top
from .db_converters import DBConverters
from .lvladmin import LevelAdmin
from .profiles import Profiles
from .top import Top


class LevelerCommands(
Profiles,
DataBase,
Top,
DBConverters,
metaclass=CompositeMetaClass
Profiles, DataBase, Top, LevelAdmin, DBConverters, metaclass=CompositeMetaClass
):
"""Class joining all command subclasses"""
15 changes: 8 additions & 7 deletions leveler/commands/database.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from ..abc import MixinMeta, CompositeMetaClass
import discord
from tabulate import tabulate
from redbot.core import commands
from redbot.core.utils import chat_formatting as chat
from tabulate import tabulate

from ..abc import CompositeMetaClass, MixinMeta


class DataBase(MixinMeta, metaclass=CompositeMetaClass):
Expand Down Expand Up @@ -33,7 +34,7 @@ async def host(self, ctx, host: str = "localhost"):
if not client:
return await message.edit(
content=message.content.replace("Now trying to connect to the new host...", "")
+ "Failed to connect. Please try again with a valid host."
+ "Failed to connect. Please try again with a valid host."
)
await message.edit(
content=message.content.replace("Now trying to connect to the new host...", "")
Expand All @@ -50,7 +51,7 @@ async def port(self, ctx, port: int = 27017):
if not client:
return await message.edit(
content=message.content.replace("Now trying to connect to the new port...", "")
+ "Failed to connect. Please try again with a valid port."
+ "Failed to connect. Please try again with a valid port."
)
await message.edit(
content=message.content.replace("Now trying to connect to the new port...", "")
Expand All @@ -66,7 +67,7 @@ async def credentials(self, ctx, username: str = None, password: str = None):
if not client:
return await message.edit(
content=message.content.replace("Now trying to connect...", "")
+ "Failed to connect. Please try again with valid credentials."
+ "Failed to connect. Please try again with valid credentials."
)
await message.edit(content=message.content.replace("Now trying to connect...", ""))

Expand All @@ -79,6 +80,6 @@ async def dbname(self, ctx, dbname: str = "leveler"):
if not client:
return await message.edit(
content=message.content.replace("Now trying to connect...", "")
+ "Failed to connect. Please try again with a valid db name."
+ "Failed to connect. Please try again with a valid db name."
)
await message.edit(content=message.content.replace("Now trying to connect...", ""))
await message.edit(content=message.content.replace("Now trying to connect...", ""))
8 changes: 2 additions & 6 deletions leveler/commands/db_converters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from leveler.abc import CompositeMetaClass
from .basecmd import DBConvertersBaseCMD

from .meesix import MeeSix


class DBConverters(
MeeSix,
metaclass=CompositeMetaClass
):
class DBConverters(MeeSix, metaclass=CompositeMetaClass):
"""Database converters commands"""

3 changes: 2 additions & 1 deletion leveler/commands/db_converters/basecmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from leveler.abc import CompositeMetaClass
from redbot.core import commands

from leveler.abc import CompositeMetaClass


class DBConvertersBaseCMD(metaclass=CompositeMetaClass):
@commands.group()
Expand Down
4 changes: 3 additions & 1 deletion leveler/commands/db_converters/meesix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from redbot.core.utils import AsyncIter
from redbot.core.utils.predicates import MessagePredicate

from .basecmd import DBConvertersBaseCMD
from leveler.abc import MixinMeta

from .basecmd import DBConvertersBaseCMD


class MeeSix(MixinMeta):
"""Mee6 leveling converter"""

lvlconvert = getattr(DBConvertersBaseCMD, "lvlconvert")

@lvlconvert.group()
Expand Down
11 changes: 11 additions & 0 deletions leveler/commands/lvladmin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from leveler.abc import CompositeMetaClass

from .backgrounds import Backgrounds
from .economy import Economy
from .roles import Roles
from .settings import Settings
from .users import Users


class LevelAdmin(Backgrounds, Economy, Roles, Settings, Users, metaclass=CompositeMetaClass):
"""Database converters commands"""
132 changes: 132 additions & 0 deletions leveler/commands/lvladmin/backgrounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
from redbot.core import commands

from leveler.abc import MixinMeta

from .basecmd import LevelAdminBaseCMD


class Backgrounds(MixinMeta):
"""Backgrounds administration commands"""

lvladmin = getattr(LevelAdminBaseCMD, "lvladmin")

@lvladmin.group(name="bg")
async def lvladminbg(self, ctx):
"""Admin background configuration"""
pass

@commands.is_owner()
@lvladminbg.command()
@commands.guild_only()
async def addprofilebg(self, ctx, name: str, url: str):
"""Add a profile background.
The proportions must be 290px x 290px."""
backgrounds = await self.config.backgrounds()
if name in backgrounds["profile"].keys():
await ctx.send("**That profile background name already exists!**")
elif not await self._valid_image_url(url):
await ctx.send("**That is not a valid image URL!**")
else:
async with self.config.backgrounds() as backgrounds:
backgrounds["profile"][name] = url
await ctx.send("**New profile background (`{}`) added.**".format(name))

@commands.is_owner()
@lvladminbg.command()
@commands.guild_only()
async def addrankbg(self, ctx, name: str, url: str):
"""Add a rank background.
The proportions must be 360px x 100px."""
backgrounds = await self.config.backgrounds()
if name in backgrounds["profile"].keys():
await ctx.send("**That rank background name already exists!**")
elif not await self._valid_image_url(url):
await ctx.send("**That is not a valid image URL!**")
else:
async with self.config.backgrounds() as backgrounds:
backgrounds["rank"][name] = url
await ctx.send("**New rank background (`{}`) added.**".format(name))

@commands.is_owner()
@lvladminbg.command()
@commands.guild_only()
async def addlevelbg(self, ctx, name: str, url: str):
"""Add a level-up background.
The proportions must be 175px x 65px."""
backgrounds = await self.config.backgrounds()
if name in backgrounds["levelup"].keys():
await ctx.send("**That level-up background name already exists!**")
elif not await self._valid_image_url(url):
await ctx.send("**That is not a valid image URL!**")
else:
async with self.config.backgrounds() as backgrounds:
backgrounds["levelup"][name] = url
await ctx.send("**New level-up background (`{}`) added.**".format(name))

@commands.is_owner()
@lvladminbg.command()
@commands.guild_only()
async def setcustombg(self, ctx, bg_type: str, user_id: str, img_url: str):
"""Set one-time custom background
bg_type can be: `profile`, `rank` or `levelup`."""
valid_types = ["profile", "rank", "levelup"]
type_input = bg_type.lower()

if type_input not in valid_types:
await ctx.send("**Please choose a valid type. Must be `profile`, `rank` or `levelup`.")
return

# test if valid user_id
userinfo = await self.db.users.find_one({"user_id": str(user_id)})
if not userinfo:
await ctx.send("**That is not a valid user id!**")
return

if not await self._valid_image_url(img_url):
await ctx.send("**That is not a valid image URL!**")
return

await self.db.users.update_one(
{"user_id": str(user_id)}, {"$set": {"{}_background".format(type_input): img_url}},
)
await ctx.send("**User {} custom {} background set.**".format(user_id, bg_type))

@commands.is_owner()
@lvladminbg.command()
@commands.guild_only()
async def delprofilebg(self, ctx, name: str):
"""Delete a profile background."""
bgs = await self.config.backgrounds()
if name in bgs["profile"].keys():
await self.config.clear_raw("backgrounds", "profile", name)
await ctx.send("**The profile background(`{}`) has been deleted.**".format(name))
else:
await ctx.send("**That profile background name doesn't exist.**")

@commands.is_owner()
@lvladminbg.command()
@commands.guild_only()
async def delrankbg(self, ctx, name: str):
"""Delete a rank background."""
bgs = await self.config.backgrounds()
if name in bgs["rank"].keys():
await self.config.clear_raw("backgrounds", "rank", name)
await ctx.send("**The rank background(`{}`) has been deleted.**".format(name))
else:
await ctx.send("**That rank background name doesn't exist.**")

@commands.is_owner()
@lvladminbg.command()
@commands.guild_only()
async def dellevelbg(self, ctx, name: str):
"""Delete a level background."""
bgs = await self.config.backgrounds()
if name in bgs["levelup"].keys():
await self.config.clear_raw("backgrounds", "levelup", name)
await ctx.send("**The level-up background(`{}`) has been deleted.**".format(name))
else:
await ctx.send("**That level-up background name doesn't exist.**")
12 changes: 12 additions & 0 deletions leveler/commands/lvladmin/basecmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import discord
from redbot.core import commands

from leveler.abc import CompositeMetaClass


class LevelAdminBaseCMD(metaclass=CompositeMetaClass):
@commands.admin_or_permissions(manage_guild=True)
@commands.group()
@commands.guild_only()
async def lvladmin(self, ctx):
"""Admin options features."""
43 changes: 43 additions & 0 deletions leveler/commands/lvladmin/economy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from redbot.core import bank, commands

from leveler.abc import MixinMeta

from .basecmd import LevelAdminBaseCMD


# noinspection PyUnusedLocal
async def non_global_bank(ctx):
return not await bank.is_global()


class Economy(MixinMeta):
"""Economy administration commands"""

lvladmin = getattr(LevelAdminBaseCMD, "lvladmin")

@lvladmin.command()
@commands.guild_only()
@commands.check(non_global_bank)
async def msgcredits(self, ctx, currency: int = 0):
"""Credits per message logged.
Default to `0`."""
server = ctx.guild

if currency < 0 or currency > 1000:
await ctx.send("**Please enter a valid number between 0 and 1000.**")
return

await self.config.guild(server).msg_credits.set(currency)
await ctx.send("**Credits per message logged set to `{}`.**".format(currency))

@commands.is_owner()
@lvladmin.command()
@commands.guild_only()
async def setprice(self, ctx, price: int):
"""Set a price for background changes."""
if price < 0:
await ctx.send("**That is not a valid background price.**")
else:
await self.config.bg_price.set(price)
await ctx.send(f"**Background price set to: `{price}`!**")
Loading

0 comments on commit 3e0780a

Please sign in to comment.