diff --git a/bot.py b/bot.py index 8a9ca48..8d71aaa 100644 --- a/bot.py +++ b/bot.py @@ -1,21 +1,22 @@ # Imports +from secrets import TOKEN + import hikari import lightbulb -from secrets import TOKEN + from database import Database as db from extensions.economy import EconomyHelperMethods as helper_methods # Setups for bot -bot = lightbulb.BotApp( - token = TOKEN, - prefix = ('coin ', 'coin.'), - default_enabled_guilds = (872490089731723365) -) +bot = lightbulb.BotApp(token=TOKEN, + prefix=("coin ", "coin."), + default_enabled_guilds=(872490089731723365)) db.initialise() bot.load_extensions("extensions.moderation") bot.load_extensions("extensions.fun") + # Events @bot.listen(hikari.GuildJoinEvent) async def on_server_join(event): @@ -23,13 +24,12 @@ async def on_server_join(event): roles = role.values() # Create roles if not exists - if 'Muted' not in roles: - await event.app.rest.create_role( - guild = event.guild_id, - name = 'Muted', - color = 0x363636, - send_messages = False - ) + if "Muted" not in roles: + await event.app.rest.create_role(guild=event.guild_id, + name="Muted", + color=0x363636, + send_messages=False) + # Running the bot -bot.run() \ No newline at end of file +bot.run() diff --git a/database.py b/database.py index 0471607..c83ee11 100644 --- a/database.py +++ b/database.py @@ -1,9 +1,10 @@ import sqlite3 -class Database (): + +class Database: """ class `Database` - + Carries methods related to the SQL bot database. """ @@ -19,7 +20,7 @@ def initialise(): """ # Connection and cursor - CONN = sqlite3.connect('bot.db') + CONN = sqlite3.connect("bot.db") cursor = CONN.cursor() ECONOMY_TABLE = """CREATE TABLE IF NOT EXISTS Economy ( @@ -34,9 +35,10 @@ def initialise(): user_name text, duration integer ); """ - + cursor.execute(ECONOMY_TABLE) cursor.execute(MUTED_PEOPLE_TABLE) -if __name__ == '__main__': - Database.initialise() \ No newline at end of file + +if __name__ == "__main__": + Database.initialise() diff --git a/extensions/economy.py b/extensions/economy.py index 2aa4694..a69518a 100644 --- a/extensions/economy.py +++ b/extensions/economy.py @@ -1,8 +1,9 @@ # Imports +import os +import sys + import hikari import lightbulb -import sys -import os # Adds a path for importing database which requires a relative import # Thanks to https://stackoverflow.com/questions/7505988/importing-from-a-relative-path-in-python @@ -12,8 +13,10 @@ economy_plugin = lightbulb.Plugin("Economy") + # Helper methods class EconomyHelperMethods: + async def __init__(self, db): self.db = db db.initialise() @@ -33,10 +36,10 @@ async def get_bank_data(): async def delete_account(): pass + # Commands @economy_plugin.command -@lightbulb.command(aliases = ['bal']) +@lightbulb.command(aliases=["bal"]) @lightbulb.implements(lightbulb.PrefixCommand, lightbulb.SlashCommand) async def balance(ctx): pass - diff --git a/extensions/fun.py b/extensions/fun.py index 95e9bb7..a6591a4 100644 --- a/extensions/fun.py +++ b/extensions/fun.py @@ -3,15 +3,18 @@ fun_plugin = lightbulb.Plugin("Fun Commands") + @fun_plugin.command -@lightbulb.command('hello', 'Says "Hello World!"') +@lightbulb.command("hello", 'Says "Hello World!"') @lightbulb.implements(lightbulb.PrefixCommand, lightbulb.SlashCommand) async def hello(ctx): - await ctx.respond('Hello World!') + await ctx.respond("Hello World!") + # Loading def load(bot): bot.add_plugin(fun_plugin) + def unload(bot): bot.remove_plugin(fun_plugin) diff --git a/extensions/moderation.py b/extensions/moderation.py index 7ab8bea..9259622 100644 --- a/extensions/moderation.py +++ b/extensions/moderation.py @@ -1,12 +1,14 @@ # Imports +import os +import sys +import time + import hikari import lightbulb -import time -import sys -import os moderation_plugin = lightbulb.Plugin("Moderation") + # Time converter def time_converter(time): """ @@ -17,48 +19,56 @@ def time_converter(time): 7d -> 7 days -> 604,800s """ + @moderation_plugin.command -@lightbulb.option('reason', 'Reason for muting the user.', type = str) -@lightbulb.option('time', 'Time duration of the mute.') -@lightbulb.option('user', 'User to be muted.', type = hikari.Member) -@lightbulb.command('mute', 'Mutess a user for a specified time interval.') +@lightbulb.option("reason", "Reason for muting the user.", type=str) +@lightbulb.option("time", "Time duration of the mute.") +@lightbulb.option("user", "User to be muted.", type=hikari.Member) +@lightbulb.command("mute", "Mutess a user for a specified time interval.") @lightbulb.implements(lightbulb.SlashCommand, lightbulb.PrefixCommand) async def mute(ctx): - await ctx.respond(f'{ctx.options.user} has been muted for {ctx.options.time}.') - await ctx.respond(f'Reason: {ctx.options.reason}.') + await ctx.respond( + f"{ctx.options.user} has been muted for {ctx.options.time}.") + await ctx.respond(f"Reason: {ctx.options.reason}.") @moderation_plugin.command -@lightbulb.option('reason', 'Reason for kicking the user.', type = str) -@lightbulb.option('user', 'User to be kicked.', type = hikari.Member) -@lightbulb.command('kick', 'Kicks a user from the guild.') +@lightbulb.option("reason", "Reason for kicking the user.", type=str) +@lightbulb.option("user", "User to be kicked.", type=hikari.Member) +@lightbulb.command("kick", "Kicks a user from the guild.") @lightbulb.implements(lightbulb.SlashCommand, lightbulb.PrefixCommand) async def kick(ctx): - await ctx.options.user.kick(reason = ctx.options.reason) - await ctx.respond(f'{ctx.options.user} has been kicked from the server.') - await ctx.respond(f'Reason: {ctx.options.reason}') + await ctx.options.user.kick(reason=ctx.options.reason) + await ctx.respond(f"{ctx.options.user} has been kicked from the server.") + await ctx.respond(f"Reason: {ctx.options.reason}") + @moderation_plugin.command -@lightbulb.option('reason', 'Reason for banning the user.', type = str) -@lightbulb.option('days_delete', 'deletes the messages specified by this property.', type = int) -@lightbulb.option('user', 'User to be banned.', type = hikari.Member) -@lightbulb.command('ban', 'Bans a user from the guild.') +@lightbulb.option("reason", "Reason for banning the user.", type=str) +@lightbulb.option("days_delete", + "deletes the messages specified by this property.", + type=int) +@lightbulb.option("user", "User to be banned.", type=hikari.Member) +@lightbulb.command("ban", "Bans a user from the guild.") @lightbulb.implements(lightbulb.SlashCommand, lightbulb.PrefixCommand) async def ban(ctx): - await ctx.options.user.ban(delete_message_days = ctx.options.days_delete, reason = ctx.options.reason) + await ctx.options.user.ban(delete_message_days=ctx.options.days_delete, + reason=ctx.options.reason) + @moderation_plugin.command -@lightbulb.option('reason', 'Reason for unbanning the user.', type = str) -@lightbulb.option('user', 'User to be unbanned.', type = hikari.Member) -@lightbulb.command('unban', 'Unbans a user from the guild.') +@lightbulb.option("reason", "Reason for unbanning the user.", type=str) +@lightbulb.option("user", "User to be unbanned.", type=hikari.Member) +@lightbulb.command("unban", "Unbans a user from the guild.") @lightbulb.implements(lightbulb.SlashCommand, lightbulb.PrefixCommand) async def unban(ctx): - await ctx.options.user.unban(reason = ctx.options.reason) + await ctx.options.user.unban(reason=ctx.options.reason) # Loading the plugin def load(bot): bot.add_plugin(moderation_plugin) + def unload(bot): - bot.remove_plugin(moderation_plugin) \ No newline at end of file + bot.remove_plugin(moderation_plugin)