Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
efa2bcf
feat: add decorators for helping in using moderation commands
thenishantsapkota Jan 26, 2022
371fc29
feat: add time conversion function
thenishantsapkota Jan 26, 2022
f573d3f
feat : add some more error classes
thenishantsapkota Jan 26, 2022
fe1f71c
feat: add 'get' function
thenishantsapkota Jan 26, 2022
ab24b71
feat: add '__init__' for Moderation folder
thenishantsapkota Jan 26, 2022
7b06093
feat: add helper commands to assist moderation commands in running
thenishantsapkota Jan 26, 2022
9161e9e
feat: add 'timeout' command
thenishantsapkota Jan 26, 2022
3ec7bb8
refactor: changed command type of timeout command
thenishantsapkota Jan 27, 2022
77e4a80
refactor: remove unnecessary imports
thenishantsapkota Jan 27, 2022
0261585
feat: add models for setting staff roles of the server
thenishantsapkota Jan 27, 2022
5e9b544
feat: add 'case search' 'case list' and started logging moderation ac…
thenishantsapkota Jan 27, 2022
4c6a46f
refactor: change role commands to config command and add a command to…
thenishantsapkota Jan 27, 2022
2289c2d
feat: add check for mod logs
thenishantsapkota Jan 27, 2022
d37b730
refactor: remove unnecessary imports
thenishantsapkota Jan 27, 2022
9a8657c
refactor: move all the time functions from 'time.py' to 'helper_funct…
thenishantsapkota Jan 27, 2022
f31a3fd
refactor: delete 'time.py'
thenishantsapkota Jan 27, 2022
312b718
refactor: remove 'get' function from __init__
thenishantsapkota Jan 27, 2022
17b9e74
refactor: move 'get' function from __init__.py to helper_functions.py
thenishantsapkota Jan 27, 2022
a278343
refactor: add a way to remove modlog channel
thenishantsapkota Jan 27, 2022
297113f
feat: add 'delete_moderation_roles' function in assisting in deleting…
thenishantsapkota Jan 27, 2022
2ac573f
refactor: remove 'config clear' command and made the roles deletable …
thenishantsapkota Jan 27, 2022
b960235
feat: add `kick` command
thenishantsapkota Jan 29, 2022
cc07724
feat: add a method for registering moderation cases
thenishantsapkota Jan 29, 2022
fd7eefc
refactor: change parameters of the `register_cases` function and add …
thenishantsapkota Jan 29, 2022
7940230
refactor: update `register_cases` function call according to the defi…
thenishantsapkota Jan 29, 2022
9cb2b14
refactor: add docstrings and make `higher_role_check` function synchr…
thenishantsapkota Jan 29, 2022
6d5a3ad
refactor: add more docstrings to all the functions
thenishantsapkota Jan 29, 2022
3bbcea0
refactor: move `on_error` from `peacebot.core.utils.errors` to `peace…
thenishantsapkota Jan 29, 2022
41ae93e
refactor: remove unnecessary imports and unnecessary logger
thenishantsapkota Jan 29, 2022
253910c
refactor: add `higher_role_check` and move `ModerationError` to `peac…
thenishantsapkota Jan 29, 2022
f14e088
refactor: move `PermissionsError` to `peacebot.core.utils.errors`
thenishantsapkota Jan 29, 2022
3e1afc6
refactor: move `CommandError` to `peacebot.core.utils.errors`
thenishantsapkota Jan 29, 2022
5132608
refactor: move `MusicError` to `peacebot.core.utils.errors`
thenishantsapkota Jan 29, 2022
7e80ff4
refactor: move all the errors from all the other files to this file
thenishantsapkota Jan 29, 2022
b983319
feat: add ModLogs model
thenishantsapkota Jan 29, 2022
600b18a
dependencies: update the project dependencies
thenishantsapkota Jan 29, 2022
ff1accf
refactor: remove unnecessary imports
thenishantsapkota Jan 29, 2022
51ed545
feat: add `ban` command
thenishantsapkota Jan 29, 2022
783f72f
refactor: make `guild`a ForeignKeyField for ModLogs and ModerationRol…
thenishantsapkota Jan 30, 2022
755f33e
dependencies: bump `hikari-miru` to v0.6.3 and use commit hash for `h…
thenishantsapkota Jan 30, 2022
25912ca
dependencies: use commit hash for `hikari` since only using hash for…
thenishantsapkota Jan 30, 2022
27f5daf
refactor: change `avatar` and `userinfo` command to Context Menu comm…
thenishantsapkota Jan 30, 2022
4d0a4c7
refactor: change from f-strings to format in the case list command
thenishantsapkota Feb 3, 2022
21af4a0
dependencies: update all the dependencies to their latest version
thenishantsapkota Mar 13, 2022
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
Empty file modified .dockerignore
100644 → 100755
Empty file.
Empty file modified .env.example
100644 → 100755
Empty file.
Empty file modified .github/dependabot.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/black.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/codeql.yml
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# Python Stuffs
__pycache__/

# Config Stuffs
.env

Expand All @@ -10,4 +9,7 @@ aerich.ini
migrations/

# Cache
*.pickle
*.pickle

# Random Stuff
test.py
Empty file modified .pre-commit-config.yaml
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions .vscode/settings.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
"source.organizeImports": true
}
},
"python.linting.pylintEnabled": false
}
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": false,
"python.linting.enabled": false
}
Empty file modified Dockerfile
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified Makefile
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified docker-compose.yml
100644 → 100755
Empty file.
37 changes: 37 additions & 0 deletions models.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class GuildModel(CustomModel):
max_length=10,
description="Custom Prefix for the guild",
)
mod_log_channel = fields.BigIntField(
description="Mod Log channel for the guild!", null=True
)

class Meta:
"""Class to set the table name and description"""
Expand Down Expand Up @@ -63,3 +66,37 @@ class Meta:
table = "autoresponses"
table_description = "Represents the autoresponses for each GuildModel"
unique_together = (("guild", "trigger"),)


class ModerationRoles(CustomModel):
id = fields.IntField(pk=True)
admin_role = fields.BigIntField(description="ID of the Admin role", null=True)
mod_role = fields.BigIntField(description="ID of the Mod role", null=True)
moderation_role = fields.BigIntField(
description="ID of the General Moderation Role", null=True
)
guild = fields.ForeignKeyField("main.GuildModel", related_name="ModerationRoles")

class Meta:
table = "staff_roles"
table_description = "Stores the roles for the moderation"
unique = "guild"


class ModLogs(CustomModel):
id = fields.IntField(description="ID of the Case", pk=True)
guild = fields.ForeignKeyField("main.GuildModel", related_name="ModLogs")
moderator = fields.TextField(description="Moderator that performed the action")
target = fields.TextField(description="Victim of the moderation action")
reason = fields.TextField(description="Reason of Moderation Action")
type = fields.TextField(description="Type of Moderation action")
timestamp = fields.DatetimeField(
description="Timestamp of the action", auto_now=True
)
message = fields.TextField(description="Message Link of the action")
channel = fields.TextField(description="Channel of action")

class Meta:
table = "mod_logs"
table_description = "Stores all the moderation actions"
unique = "guild"
2 changes: 0 additions & 2 deletions peacebot/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from .config import bot_config, db_config, lavalink_config

__all__ = ["bot_config", "db_config"]
Empty file modified peacebot/__main__.py
100644 → 100755
Empty file.
Empty file modified peacebot/assets/__init__.py
100644 → 100755
Empty file.
Empty file modified peacebot/assets/banner.txt
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions peacebot/config/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .bot import bot_config
from .database import db_config
from .lavalink import lavalink_config

__all__ = ["bot_config", "db_config", "lavalink_config"]
1 change: 1 addition & 0 deletions peacebot/config/bot.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BotConfig(BaseSettings):
token: str
prefix: str
test_guilds: list[int]
log_webhook: int

class Config:
env_file = ".env"
Expand Down
Empty file modified peacebot/config/database.py
100644 → 100755
Empty file.
Empty file modified peacebot/config/lavalink.py
100644 → 100755
Empty file.
Empty file modified peacebot/config/reddit.py
100644 → 100755
Empty file.
3 changes: 0 additions & 3 deletions peacebot/core/bot.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import asyncio
import logging
from pathlib import Path

import aioredis
import hikari
Expand All @@ -20,7 +19,6 @@
from peacebot.core.event_handler import EventHandler
from peacebot.core.utils.activity import CustomActivity
from peacebot.core.utils.embed_colors import EmbedColors
from peacebot.core.utils.errors import on_error
from tortoise_config import tortoise_config

logger = logging.getLogger("peacebot.main")
Expand Down Expand Up @@ -74,7 +72,6 @@ def run(self) -> None:
self.event_manager.subscribe(hikari.StartedEvent, self.on_started)
self.event_manager.subscribe(hikari.StoppingEvent, self.on_stopping)
self.event_manager.subscribe(hikari.StoppedEvent, self.on_stopped)
self.event_manager.subscribe(lightbulb.CommandErrorEvent, on_error)
self.event_manager.subscribe(hikari.ShardReadyEvent, self.on_shard_ready)
self.event_manager.subscribe(hikari.GuildMessageCreateEvent, self.on_message)

Expand Down
Empty file modified peacebot/core/event_handler.py
100644 → 100755
Empty file.
5 changes: 1 addition & 4 deletions peacebot/core/plugins/Admin/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import lightbulb

from peacebot.core.utils.embed_colors import EmbedColors


class CommandError(lightbulb.LightbulbError):
pass
from peacebot.core.utils.errors import CommandError


async def handle_plugins(ctx: lightbulb.Context, plugin_str: str, action: str) -> None:
Expand Down
77 changes: 77 additions & 0 deletions peacebot/core/plugins/Admin/admin.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import math
import re

import hikari
import lightbulb

from models import GuildModel
from peacebot.core.utils.embed_colors import EmbedColors

admin_plugin = lightbulb.Plugin(
name="Admin", description="Admin commands for the server"
Expand All @@ -24,6 +28,79 @@ async def changeprefix(ctx: lightbulb.Context) -> None:
await ctx.respond(f"I set your guild's prefix to `{prefix}`")


@admin_plugin.listener(lightbulb.CommandErrorEvent)
async def on_error(event: lightbulb.CommandErrorEvent) -> None:

error = event.exception
if isinstance(error, lightbulb.CommandNotFound):
return

if isinstance(error, lightbulb.BotMissingRequiredPermission):
missing = [
perm.replace("_", " ").replace("guild", "server").title()
for perm in str(error.missing_perms).split("|")
]
if len(missing) > 2:
fmt = "{}, and {}".format("**, **".join(missing[:-1]), missing[-1])
else:
fmt = " and ".join(missing)

_message = f"I need the **{fmt}** permission(s) to run this command."

embed = hikari.Embed(
title="I am Missing Permissions",
color=EmbedColors.ALERT,
description=_message,
)
return await event.context.respond(
embed=embed, flags=hikari.MessageFlag.EPHEMERAL
)

if isinstance(error, lightbulb.CommandIsOnCooldown):
embed = hikari.Embed(
title="Command on Cooldown",
color=EmbedColors.ALERT,
description=f"This command is on cooldown, please retry in {math.ceil(error.retry_after)}s.",
)
return await event.context.respond(
embed=embed, flags=hikari.MessageFlag.EPHEMERAL
)

if isinstance(error, lightbulb.NotEnoughArguments):
return await event.bot.help_command.send_command_help(
event.context, event.context.command
)

if isinstance(error, lightbulb.MissingRequiredPermission):
missing = [
perm.replace("_", " ").replace("guild", "server").title()
for perm in str(error.missing_perms).split("|")
]
if len(missing) > 2:
fmt = "{}, and {}".format("**, **".join(missing[:-1]), missing[-1])
else:
fmt = " and ".join(missing)
_message = "You need the **{}** permission(s) to use this command.".format(fmt)

embed = hikari.Embed(
title="You are missing permissions",
color=EmbedColors.ALERT,
description=_message,
)
return await event.context.respond(
embed=embed, flags=hikari.MessageFlag.EPHEMERAL
)

title = " ".join(re.compile(r"[A-Z][a-z]*").findall(error.__class__.__name__))
await event.context.respond(
embed=hikari.Embed(
title=title, description=str(error), color=EmbedColors.ALERT
),
flags=hikari.MessageFlag.EPHEMERAL,
)
raise error


def load(bot: lightbulb.BotApp) -> None:
bot.add_plugin(admin_plugin)

Expand Down
10 changes: 5 additions & 5 deletions peacebot/core/plugins/Admin/owner.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import yuyo
from lightbulb.utils import nav

import peacebot.core.utils.helper_functions as hf
from peacebot.core.utils.helper_functions import error_handler

from . import CommandError, handle_plugins

Expand Down Expand Up @@ -76,7 +76,7 @@ async def eval_python_code_no_capture(ctx: lightbulb.Context, code: str) -> None
@lightbulb.set_help(docstring=True)
@lightbulb.command("eval", "Run Evals as Bot owner")
@lightbulb.implements(lightbulb.PrefixCommand)
@hf.error_handler()
@error_handler()
async def eval_command(ctx: lightbulb.Context) -> None:
"""
Dynamically evaluate a script in the bot's environment.
Expand Down Expand Up @@ -113,7 +113,7 @@ async def eval_command(ctx: lightbulb.Context) -> None:
@lightbulb.option("plugin", "Name of the plugin")
@lightbulb.command("reload", "Reload a specific plugin.")
@lightbulb.implements(lightbulb.SlashCommand, lightbulb.PrefixCommand)
@hf.error_handler()
@error_handler()
async def reload_plugin(ctx: lightbulb.Context) -> None:
plugin = ctx.options.plugin
await handle_plugins(ctx, plugin, "reload")
Expand All @@ -123,7 +123,7 @@ async def reload_plugin(ctx: lightbulb.Context) -> None:
@lightbulb.option("plugin", "Name of the plugin")
@lightbulb.command("unload", "Unload a specific plugin.")
@lightbulb.implements(lightbulb.SlashCommand, lightbulb.PrefixCommand)
@hf.error_handler()
@error_handler()
async def unload_plugin(ctx: lightbulb.Context) -> None:
plugin = ctx.options.plugin
if plugin in [
Expand All @@ -139,7 +139,7 @@ async def unload_plugin(ctx: lightbulb.Context) -> None:
@lightbulb.option("plugin", "Name of the plugin")
@lightbulb.command("load", "Load a specific plugin.")
@lightbulb.implements(lightbulb.SlashCommand, lightbulb.PrefixCommand)
@hf.error_handler()
@error_handler()
async def load_plugin(ctx: lightbulb.Context) -> None:
plugin = ctx.options.plugin
await handle_plugins(ctx, plugin, "load")
Expand Down
Empty file modified peacebot/core/plugins/AutoResponse/__init__.py
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions peacebot/core/plugins/AutoResponse/autoresponse.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import hikari
import lightbulb

import peacebot.core.utils.helper_functions as hf
from models import AutoResponseModel, GuildModel
from peacebot.core.utils.embed_colors import EmbedColors
from peacebot.core.utils.helper_functions import error_handler

from . import AutoResponseError, clone_autoresponse, handle_message, is_valid_uuid

Expand Down Expand Up @@ -234,7 +234,7 @@ async def autoresponse_export(ctx: lightbulb.Context) -> None:
@lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.MANAGE_GUILD))
@lightbulb.command("import", "Import autoreponse(s) from another server")
@lightbulb.implements(lightbulb.PrefixSubCommand, lightbulb.SlashSubCommand)
@hf.error_handler()
@error_handler()
async def autoresponse_import(ctx: lightbulb.Context) -> None:
_id: str = ctx.options.id
if _id == str(ctx.guild_id):
Expand Down Expand Up @@ -291,7 +291,7 @@ async def autoresponse_import(ctx: lightbulb.Context) -> None:
@lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.MANAGE_GUILD))
@lightbulb.command("toggle", "Enable or disable the autoresponse", aliases=["tgl"])
@lightbulb.implements(lightbulb.PrefixSubCommand, lightbulb.SlashSubCommand)
@hf.error_handler()
@error_handler()
async def autoresponse_toggle(ctx: lightbulb.Context) -> None:
autoresponse = await AutoResponseModel.get_or_none(
guild__id=ctx.guild_id, trigger__iexact=ctx.options.trigger
Expand Down
Empty file modified peacebot/core/plugins/Fun/__init__.py
100644 → 100755
Empty file.
Empty file modified peacebot/core/plugins/Fun/animals.py
100644 → 100755
Empty file.
Empty file modified peacebot/core/plugins/Fun/nsfw.py
100644 → 100755
Empty file.
10 changes: 1 addition & 9 deletions peacebot/core/plugins/Miscellaneous/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import lightbulb
from apscheduler.schedulers.asyncio import AsyncIOScheduler

from peacebot.core.utils.time import TimeConverter


def fetch_scheduler(ctx: lightbulb.Context) -> AsyncIOScheduler:
return ctx.bot.d.scheduler


async def convert_time(ctx: lightbulb.Context, time: str) -> float:
seconds = await TimeConverter.convert(TimeConverter, ctx, time)

return seconds
return ctx.bot.scheduler


async def send_remainder(ctx: lightbulb.Context, text: str) -> None:
Expand Down
Loading