Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# 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):
role = event.app.cache.get_roles_view_for_guild(event.guild)
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()
bot.run()
14 changes: 8 additions & 6 deletions database.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sqlite3

class Database ():

class Database:
"""
class `Database`

Carries methods related to the SQL bot database.
"""

Expand All @@ -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 (
Expand All @@ -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()

if __name__ == "__main__":
Database.initialise()
11 changes: 7 additions & 4 deletions extensions/economy.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,8 +13,10 @@

economy_plugin = lightbulb.Plugin("Economy")


# Helper methods
class EconomyHelperMethods:

async def __init__(self, db):
self.db = db
db.initialise()
Expand All @@ -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

7 changes: 5 additions & 2 deletions extensions/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
60 changes: 35 additions & 25 deletions extensions/moderation.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand All @@ -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)
bot.remove_plugin(moderation_plugin)