-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
723 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.**") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`!**") |
Oops, something went wrong.