Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Unfinished work (obsolete) (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shibzel authored Oct 28, 2023
2 parents eda5e0e + ac2ec59 commit afb6076
Show file tree
Hide file tree
Showing 59 changed files with 139 additions and 120 deletions.
Empty file modified .github/ISSUE_TEMPLATE/bug_report.md
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/feature_request.md
100644 → 100755
Empty file.
Empty file modified .github/PRIVACY_POLICY.md
100644 → 100755
Empty file.
Empty file modified .github/SECURITY.md
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
28 changes: 16 additions & 12 deletions Shibbot.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
from src.core import Shibbot, PterodactylShibbot
from src.logging import Logger, ANSIEscape, LoggingLevel
except ModuleNotFoundError as exc:
raise ImportError("An import error occured."
" Be sure you installed all the requirements modules or using a correct version of Python.") from exc
raise ImportError("An import error occurred."
" Be sure you installed all the requirements modules or using a correct version of Python."
"\nEntering this in your terminal could help :\n python3 -m pip install -r requirements.txt") from exc


CONFIG_FILE_PATH = "./config.toml"
Expand All @@ -34,7 +35,7 @@ class Syntax(ConfigError, TypeError):
"""Raised when there is a syntax problem or an type problem."""

class UncompletedOrMissing(ConfigError):
"""Raised when the a line in the cofig file is uncompleted or missing."""
"""Raised when the a line in the config file is uncompleted or missing."""


def ascii_art(splash_text_fp: str, logger: Logger):
Expand All @@ -43,7 +44,7 @@ def ascii_art(splash_text_fp: str, logger: Logger):
with open(splash_text_fp, "rb") as f:
splash_text = toml.load(f)["SplashText"]
except (FileNotFoundError, toml.TOMLDecodeError) as err:
logger.error("An error occured while loading splash texts.", err)
logger.error("An error occurred while loading splash texts.", err)
splash_text = ("placeholder",)
print(f"""
ᵛᵉʷʸ ᵖᵒʷᵉʳᶠᵘˡ
Expand All @@ -64,20 +65,21 @@ def ascii_art(splash_text_fp: str, logger: Logger):

def main(
config_fp: str = CONFIG_FILE_PATH,
config_exemple_fp: str = CONFIG_FILE_PATH + ".exemple",
config_example_fp: str = CONFIG_FILE_PATH + ".example",
splash_text_dp: str = SPLASH_TEXT_FP,
checks: bool = True,
show_ascii: bool = True
show_ascii: bool = True,
*args, **_kwargs
):
"""Main function. Do some checks and then starts the bot."""
cls = Shibbot

# Verifies if the config file exists
if not os.path.exists(config_fp):
try:
copyfile(config_exemple_fp, config_fp)
copyfile(config_example_fp, config_fp)
except FileNotFoundError as exc:
raise MissingFile(config_exemple_fp) from exc
raise MissingFile(config_example_fp) from exc
else:
raise ConfigError(
f"Please fulfill the requirements inside of the {config_fp} file.")
Expand Down Expand Up @@ -105,7 +107,7 @@ def main(

logs_path = paths["Logs"]
path_kwargs = {
"extentions_path": paths["Extensions"],
"extensions_path": paths["Extensions"],
"cache_path": paths["Cache"],
"temp_cache_path": paths["TemporaryCache"]
}
Expand Down Expand Up @@ -144,7 +146,7 @@ def main(
except (ValueError, AssertionError) as exc:
raise Syntax(
"Invalid Discord id(s)."
" Make sure that the ids are intergers (len >= 18) inside a list."
" Make sure that the ids are integers (len >= 18) inside a list."
) from exc
kwargs["instance_owners"] = instance_owners

Expand All @@ -168,7 +170,7 @@ def main(
assert len(response) > 0
last_version = response[0]["name"]
if last_version == __version__:
logger.log("You're currently using the lastest version !")
logger.log("You're currently using the latest version !")
else:
for release in response:
if release["name"] == __version__:
Expand Down Expand Up @@ -209,10 +211,12 @@ def main(
kwargs.update(parameters)
logger.debug("All checks done and settings loaded.")

kwargs.update(_kwargs)

# Starting the bot
try:
# Instancing Shibbot or PterodactylShibbot
shibbot = cls(**kwargs)
shibbot = cls(*args, **kwargs)
shibbot.run(token, command_input=console) # Running it
except Exception as err:
logger.critical("Oops... Shibbot stopped ?", err)
Expand Down
7 changes: 4 additions & 3 deletions config.toml.exemple
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# / This is a Shibbot v1 config file.
# / This is a Shibbot configuration file.
# / DO NOT EDIT if this file is named
# "config.toml.exemple".
# / Instead, copy its content into
# another file named "config.toml".
config_version = 1

[Settings]
UseConsole = true
DebugMode = false
# / If you want a better disponibility
# of ressources by caching them (uses
# / If you want a better availability
# of resources by caching them (uses
# more ram and storage)
UseCache = false
# / Disables every default cog
Expand Down
Empty file modified misc/burgir.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified misc/shibbot-egg.json
100644 → 100755
Empty file.
Empty file modified misc/splash_text.toml
100644 → 100755
Empty file.
Empty file modified requirements.txt
100644 → 100755
Empty file.
Empty file modified src/__init__.py
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions src/cogs/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import (
admin, commands, events, misc, status, fun, utils,
# ,automod, mod, music
admin, commands, events, misc, status, fun, utils, mod,
# ,automod, music
)
3 changes: 3 additions & 0 deletions src/cogs/admin.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ async def _on_cog(self, ctx, method, cog_name, method_name):
message = f"Couldn't {method_name} '{cog_name}', the following error occured :"
self.logger.error(message, error)
await ctx.send(message, file=discord.File(fp=create_log_file(self.bot, error)))

@commands.command()
@commands.is_owner()
async def reload(self, ctx: commands.Context, cog):
await self._on_cog(ctx, self.bot.reload_extension, cog, "reload")

@commands.command()
@commands.is_owner()
async def load(self, ctx: commands.Context, cog):
await self._on_cog(ctx, self.bot.load_extension, cog, "load")

@commands.command()
@commands.is_owner()
async def unload(self, ctx: commands.Context, cog):
Expand Down
Empty file modified src/cogs/automod/__init__.py
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions src/cogs/commands/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, bot: Shibbot):
languages={
"en": English(),
"fr": French(),
"shibberish": Shibberish
"shibberish": Shibberish()
},
emoji="⚙️"
)
Expand Down Expand Up @@ -182,7 +182,7 @@ async def get_infos(self, ctx: bridge.BridgeApplicationContext):
n_servers=len(self.bot.guilds),
n_users=len(self.bot.users),
owner_github="https://github.com/Shibzel",
owner=self.bot.project_owner if self.bot.project_owner else "Shibzel#1873"))
owner=self.bot.project_owner if self.bot.project_owner else "shibzel"))
specs = self.bot.specs
embed.add_field(name=lang.GET_INFOS_FIELD2_NAME,
value=lang.GET_INFOS_FIELD2_DESCRIPTION.format(
Expand Down
Empty file modified src/cogs/commands/lang/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/commands/lang/en.py
100644 → 100755
Empty file.
Empty file modified src/cogs/commands/lang/fr.py
100644 → 100755
Empty file.
Empty file modified src/cogs/commands/lang/shibberish.py
100644 → 100755
Empty file.
Empty file modified src/cogs/events/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/events/lang/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/events/lang/en.py
100644 → 100755
Empty file.
Empty file modified src/cogs/events/lang/fr.py
100644 → 100755
Empty file.
Empty file modified src/cogs/fun/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/fun/lang/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/fun/lang/en.py
100644 → 100755
Empty file.
Empty file modified src/cogs/fun/lang/fr.py
100644 → 100755
Empty file.
Empty file modified src/cogs/misc/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/misc/lang/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/misc/lang/en.py
100644 → 100755
Empty file.
Empty file modified src/cogs/misc/lang/fr.py
100644 → 100755
Empty file.
111 changes: 55 additions & 56 deletions src/cogs/mod/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,11 @@ async def when_ready(self) -> None:
if tasks:
self.logger.debug(f"Resuming {len(tasks)} tempbans and tempmutes.")
await asyncio.gather(*tasks)
else:
self.logger.debug("Nothing to do.")

async def enable_logs(self, guild_id,):
pass # TODO: Complete

async def set_log_channel(self, channel: discord.TextChannel, lang: English = None) -> None:
guild = channel.guild
db = self.bot.db
query = f"SELECT log_channel FROM {self.plugin_name} WHERE guild_id=?"
cur = db.execute(query, (guild.id,))
result = cur.fetchone()
if result:
query = f"UPDATE {self.plugin_name} SET log_channel=? WHERE guild_id=?"
else:
query = f"INSERT INTO {self.plugin_name} (log_channel, guild_id) VALUES (?, ?)"

db.execute(query, (channel.id, guild.id,))
db.commit()

if not lang:
lang = self.get_lang(guild)
embed = discord.Embed(title=lang.ON_LOG_CHANNEL_UPDATE_TITLE,
description=lang.ON_LOG_CHANNEL_UPDATE_DESCRIPTION,
color=discord.Color.green())
log_channel = self.get_log_channel(guild)
await log_channel.send(embed=embed)

def get_log_channel(self, guild: discord.Guild) -> discord.TextChannel | None:
db = self.bot.db
Expand Down Expand Up @@ -231,8 +211,6 @@ async def get_warns(self, guild: discord.Guild, user: discord.User) -> tuple[int
cur = db.execute(query, (guild.id, user.id,))
return cur.fetchall()

# CAT: Events

async def _find_entry(
self,
guild: discord.Guild,
Expand Down Expand Up @@ -386,29 +364,6 @@ async def on_warn(
description=description, color=discord.Color.orange())
await log_channel.send(embed=embed)

async def on_purge(
self,
channel: discord.TextChannel | discord.Thread,
messages: int,
moderator: discord.Member,
user: discord.User = None,
reason: str = None,
lang: English = None,
log_channel: discord.TextChannel = None
) -> None:
guild = channel.guild
if not (log_channel := log_channel or self.get_log_channel(guild)):
return
if not lang:
lang = self.get_lang(guild)

description = lang.ON_PURGE_USER_DESCRIPTION if user else lang.ON_PURGE_CHANNEL_DESCRIPTION
description = description.format(user=user, mod=moderator, messages=messages, channel=channel,
reason=reason or lang.NO_REASON_PLACEHOLDER)
embed = LogEmbed(title=lang.ON_WARN_TITLE, user=user,
description=description, color=discord.Color.yellow())
await log_channel.send(embed=embed)

async def on_mute(
self,
member: discord.Member,
Expand Down Expand Up @@ -508,8 +463,28 @@ async def on_member_join(self, member: discord.Member):
await member.add_roles(mute_role)
await self.on_mute(member, self.bot.user, "User joined while he was muted.", update_from_db=False)

# CAT: Commands

async def set_log_channel(self, channel: discord.TextChannel, lang: English = None) -> None:
guild = channel.guild
db = self.bot.db
query = f"SELECT log_channel FROM {self.plugin_name} WHERE guild_id=?"
cur = db.execute(query, (guild.id,))
result = cur.fetchone()
if result:
query = f"UPDATE {self.plugin_name} SET log_channel=? WHERE guild_id=?"
else:
query = f"INSERT INTO {self.plugin_name} (log_channel, guild_id) VALUES (?, ?)"

db.execute(query, (channel.id, guild.id,))
db.commit()

if not lang:
lang = self.get_lang(guild)
embed = discord.Embed(title=lang.ON_LOG_CHANNEL_UPDATE_TITLE,
description=lang.ON_LOG_CHANNEL_UPDATE_DESCRIPTION,
color=discord.Color.green())
log_channel = self.get_log_channel(guild)
await log_channel.send(embed=embed)

@bridge.bridge_command(
name="logs",
description="Changes the log channel.",
Expand All @@ -526,6 +501,29 @@ async def _set_log_channel(self, ctx: bridge.BridgeApplicationContext, channel:
embed = discord.Embed(title=lang.SET_LOG_CHANNEL_TITLE, description=description,
color=discord.Color.green())
await ctx.respond(embed=embed)

async def on_purge(
self,
channel: discord.TextChannel | discord.Thread,
messages: int,
moderator: discord.Member,
user: discord.User = None,
reason: str = None,
lang: English = None,
log_channel: discord.TextChannel = None
) -> None:
guild = channel.guild
if not (log_channel := log_channel or self.get_log_channel(guild)):
return
if not lang:
lang = self.get_lang(guild)

description = lang.ON_PURGE_USER_DESCRIPTION if user else lang.ON_PURGE_CHANNEL_DESCRIPTION
description = description.format(user=user, mod=moderator, messages=messages, channel=channel,
reason=reason or lang.NO_REASON_PLACEHOLDER)
embed = LogEmbed(title=lang.ON_PURGE_TITLE, user=user,
description=description, color=discord.Color.yellow())
await log_channel.send(embed=embed)

@bridge.bridge_command(
name="clear",
Expand All @@ -534,20 +532,21 @@ async def _set_log_channel(self, ctx: bridge.BridgeApplicationContext, channel:
discord.Option(int, name="limit", description="The number of messages you want to clear, maximum: 100."),
discord.Option(str, name="reason", description="Why.", required=False)
])
async def clean_messages(self, ctx: bridge.BridgeApplicationContext, limit: int, reason: str = None):
async def clear_channel(self, ctx: bridge.BridgeApplicationContext, limit: int, reason: str = None):
lang: English = self.get_lang(ctx)

limit += 1
if limit > 100:
limit = 100

async with ctx.channel.typing():
deleted_messages = len(await ctx.channel.purge(limit=limit) or ())
description = lang.CLEAN_MESSAGES_DESCRIPTION.format(
messages=deleted_messages)
await ctx.defer()
deleted_messages = len(await ctx.channel.purge(limit=limit) or ())
description = lang.CLEAN_MESSAGES_DESCRIPTION.format(
messages=deleted_messages)

embed = discord.Embed(title=lang.CLEAN_MESSAGES_TITLE, description=description,
color=discord.Color.green())
await ctx.respond(embed=embed)
await ctx.send(embed=embed)
await self.on_purge(ctx.channel, deleted_messages, ctx.author, reason=reason, lang=lang)

@bridge.bridge_command(
Expand All @@ -566,7 +565,7 @@ async def clean_user_messages(self, ctx: bridge.BridgeApplicationContext, limit:

async with ctx.channel.typing():
messages = []
after = datetime.utcnow() - timedelta(days=14-1)
after = datetime.utcnow() - timedelta(days=14-0.5)
async for message in ctx.channel.history(limit=None, after=after):
# The bot can't bulk delete messages older than 14 days
if len(messages) >= limit:
Expand Down
Empty file modified src/cogs/mod/converters.py
100644 → 100755
Empty file.
Empty file modified src/cogs/mod/lang/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/mod/lang/en.py
100644 → 100755
Empty file.
Empty file modified src/cogs/status.py
100644 → 100755
Empty file.
Empty file modified src/cogs/utils/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/utils/lang/__init__.py
100644 → 100755
Empty file.
Empty file modified src/cogs/utils/lang/en.py
100644 → 100755
Empty file.
Empty file modified src/cogs/utils/lang/fr.py
100644 → 100755
Empty file.
Empty file modified src/console/__init__.py
100644 → 100755
Empty file.
Empty file modified src/console/errors.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/constants.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
SERVER_INVITATION_LINK = "https://discord.gg/TZNWfJmPwj"
OFFICIAL_SHIBBOT_INSTANCES = (
838922957547765801, # Production
848729671083360316 # Beta
848729671083360316 # Nightly
)

DATABASE_FILE_PATH = "./database.db"
Expand Down
Loading

0 comments on commit afb6076

Please sign in to comment.