whole bunch of things

This commit is contained in:
SeaswimmerTheFsh 2023-06-21 12:06:24 -04:00
parent d63c9300ab
commit 1353b5e96b
4 changed files with 62 additions and 47 deletions

View file

@ -18,7 +18,8 @@ jobs:
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install pylint pip install pylint
pip install python-dotenv revolt.py mysql-connector-python pytimeparse2 pip install -U git+https://github.com/revoltchat/revolt.py
pip install python-dotenv mysql-connector-python pytimeparse2
- name: Analysing the code with pylint - name: Analysing the code with pylint
run: | run: |
pylint $(git ls-files '*.py') pylint $(git ls-files '*.py')

View file

@ -9,7 +9,7 @@ If you're self-hosting IndiumRevolt.py, please make it clear that it is not the
* Clone this repository (`git clone https://github.com/SeaswimmerTheFsh/IndiumRevolt.py.git`) * Clone this repository (`git clone https://github.com/SeaswimmerTheFsh/IndiumRevolt.py.git`)
* Install Revolt.py and python-dotenv * Install Revolt.py and python-dotenv
* ``pip install revolt.py python-dotenv`` * ``pip install revolt.py pytimeparse2 python-dotenv``
* Set up an `.env` file * Set up an `.env` file
* Rename the `.env.example` file and fill out the values * Rename the `.env.example` file and fill out the values
* Run the bot (`python main.py`) * Run the bot (`python main.py`)

View file

@ -20,16 +20,20 @@ class Moderation(commands.Cog):
self.bot = bot self.bot = bot
disable_dateutil() disable_dateutil()
def mysql_log(self, moderation_type, target_id, duration, reason): def mysql_connect():
moddb = mysql.connector.connect(host=db_host,user=db_user,password=db_password,database=db) connection = mysql.connector.connect(host=db_host,user=db_user,password=db_password,database=db)
cursor = moddb.cursor() return connection
cursor.execute("SELECT moderation_id FROM `mod` ORDER BY moderation_id DESC LIMIT 1")
def mysql_log(self, ctx: commands.Context,moderation_type, target_id, duration, reason):
mysql = Moderation.mysql_connect()
cursor = mysql.cursor()
cursor.execute(f"SELECT moderation_id FROM `{ctx.server.id.lower()}_moderation` ORDER BY moderation_id DESC LIMIT 1")
moderation_id = cursor.fetchone()[0] + 1 moderation_id = cursor.fetchone()[0] + 1
sql = "INSERT INTO `mod` (moderation_id, moderation_type, target_id, duration, reason, resolved) VALUES (%s, %s, %s, %s, %s, %s)" sql = f"INSERT INTO `{ctx.server.id.lower()}_moderation` (moderation_id, moderation_type, target_id, duration, reason, resolved) VALUES (%s, %s, %s, %s, %s, %s)"
val = (moderation_id, moderation_type, target_id, duration, reason, 0) val = (moderation_id, moderation_type, target_id, duration, f"{reason}", 0)
cursor.execute(sql, val) cursor.execute(sql, val)
moddb.commit() mysql.commit()
moddb.close() mysql.close()
print(f"MySQL Row Inserted!\n{moderation_id}, {moderation_type}, {target_id}, {duration}, {reason}, 0") print(f"MySQL Row Inserted!\n{moderation_id}, {moderation_type}, {target_id}, {duration}, {reason}, 0")
@commands.command(name="timeout", aliases=["mute"]) @commands.command(name="timeout", aliases=["mute"])
@ -39,21 +43,27 @@ class Moderation(commands.Cog):
except ValueError: except ValueError:
await ctx.message.reply(f"Please provide a valid duration!\nSee `{prefix}tdc`") await ctx.message.reply(f"Please provide a valid duration!\nSee `{prefix}tdc`")
return return
# await target.timeout(parsed_time) await target.timeout(parsed_time)
await ctx.message.reply(f"{target.mention} has been timed out for {str(parsed_time)}!\n**Reason** - `{reason}`") response = await ctx.message.reply(f"{target.mention} has been timed out for {str(parsed_time)}!\n**Reason** - `{reason}`")
# embeds = [revolt.SendableEmbed(title="Timed Out", description=f"You have been timed out for {str(parsed_time)}.\n### Reason\n`{reason}", colour="#5d82d1")] try:
# await target.send(embeds=embeds) embeds = [revolt.SendableEmbed(title="Timed Out", description=f"You have been timed out for {str(parsed_time)} in {ctx.server.name}.\n### Reason\n`{reason}", colour="#5d82d1")]
Moderation.mysql_log(self, moderation_type='Timeout', target_id=target.id, duration=parsed_time, reason=reason) await target.send(embeds=embeds)
except:
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
Moderation.mysql_log(self, ctx, moderation_type='Timeout', target_id=target.id, duration=parsed_time, reason=reason)
@commands.command() @commands.command()
async def warn(self, ctx: commands.Context, target: commands.MemberConverter, *, reason: str): async def warn(self, ctx: commands.Context, target: commands.MemberConverter, *, reason: str):
if not reason: if not reason:
await ctx.message.reply("Please include a reason!") await ctx.message.reply("Please include a reason!")
return return
await ctx.message.reply(f"{target.mention} has been warned!\n**Reason** - `{reason}`") response = await ctx.message.reply(f"{target.mention} has been warned!\n**Reason** - `{reason}`")
# embeds = [revolt.SendableEmbed(title="Warned", description=f"You have been warned.\n### Reason\n`{reason}", colour="#5d82d1")] try:
# await target.send(embeds=embeds) embeds = [revolt.SendableEmbed(title="Warned", description=f"You have been warned in {ctx.server.name}!\n### Reason\n`{reason}`", colour="#5d82d1")]
Moderation.mysql_log(self, moderation_type='Warning', target_id=target.id, duration='NULL', reason=reason) await target.send(embeds=embeds)
except:
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
Moderation.mysql_log(self, ctx, moderation_type='Warning', target_id=target.id, duration='NULL', reason=reason)
@commands.command() @commands.command()
async def ban(self, ctx: commands.Context, target: commands.MemberConverter, *, reason: str): async def ban(self, ctx: commands.Context, target: commands.MemberConverter, *, reason: str):
@ -61,25 +71,38 @@ class Moderation(commands.Cog):
await ctx.message.reply("Please include a reason!") await ctx.message.reply("Please include a reason!")
return return
try: try:
# embeds = [revolt.SendableEmbed(title="Banned", description=f"You have been banned.\n### Reason\n`{reason}", colour="#5d82d1")]
# await target.send(embeds=embeds)
await target.ban(reason=reason) await target.ban(reason=reason)
await ctx.message.reply(f"{target.mention} has been banned!\n**Reason** - `{reason}`") response = await ctx.message.reply(f"{target.mention} has been banned!\n**Reason** - `{reason}`")
Moderation.mysql_log(self, moderation_type='Ban', target_id=target.id, duration='NULL', reason=reason) try:
embeds = [revolt.SendableEmbed(title="Banned", description=f"You have been banned from `{ctx.server.name}`.\n### Reason\n`{reason}`", colour="#5d82d1")]
await target.send(embeds=embeds)
except:
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
Moderation.mysql_log(self, ctx, moderation_type='Ban', target_id=target.id, duration='NULL', reason=reason)
except revolt.errors.HTTPError: except revolt.errors.HTTPError:
await ctx.message.reply(f"{target.mention} is already banned!") await ctx.message.reply(f"{target.mention} is already banned!")
@commands.command() @commands.command()
async def unban(self, ctx: commands.Context, target: commands.MemberConverter): async def unban(self, ctx: commands.Context, target: commands.UserConverter, *, reason: str):
try: if ctx.channel.channel_type is not revolt.ChannelType.text_channel:
await target.unban() await ctx.message.reply("You cannot use moderation commands in direct messages!")
# embeds = [revolt.SendableEmbed(title="Unbanned", description="You have been unbanned.", colour="#5d82d1")]
# await target.send(embeds=embeds)
await ctx.message.reply(f"{target.mention} has been unbanned!")
Moderation.mysql_log(self, moderation_type='Unban', target_id=target.id, duration='NULL', reason=f'Unbanned through {prefix}unban')
except revolt.errors.HTTPError:
await ctx.message.reply(f"{target.mention} is not banned!")
return return
if not reason:
await ctx.message.reply("Please include a reason!")
return
bans = await ctx.server.fetch_bans()
for ban in bans:
if ban.user_id == target.id:
await ban.unban()
response = await ctx.message.reply(f"{target.mention} has been unbanned!\n**Reason** - `{reason}`")
try:
embeds = [revolt.SendableEmbed(title="Unbanned", description=f"You have been unbanned from `{ctx.server.name}`.\n### Reason\n`{reason}`", colour="#5d82d1")]
await target.send(embeds=embeds)
except:
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
Moderation.mysql_log(self, ctx, moderation_type='Unban', target_id=target.id, duration='NULL', reason=str(reason))
return
await ctx.message.reply(f"{target.mention} is not banned!")
@commands.command(aliases=["tdc"]) @commands.command(aliases=["tdc"])

21
main.py
View file

@ -22,21 +22,12 @@ class Client(commands.CommandsClient):
return prefix return prefix
return input return input
# async def on_message(self, message: revolt.Message): async def on_message(self, message: revolt.Message):
# if 'PREFIX' not in os.environ or prefix is None: if isinstance(message.author, revolt.Member):
# if message.author == self.user.owner: print(f"{message.author.name}#{message.author.discriminator} ({message.author.id}): {message.content}\n ⤷ Sent from {message.server.name} ({message.server.id})")
# await message.channel.send("You have started the bot without setting the `prefix` environment variable!\nIt has been set to `temp!` automatically, please change it using `temp!prefix <new prefix>`.") else:
# print("ERROR: prefix_env_var check failed! Prefix set to 'temp!'.") print(f"{message.author.name}#{message.author.discriminator} ({message.author.id}): {message.content}\n ⤷ Sent in Direct Messages")
# new_prefix = "temp!" await self.process_commands(message)
# await Client.prefix_change(self=self, message=message, new_prefix=new_prefix, silent=True)
# else:
# print("ERROR: prefix_env_var check failed!")
# else:
# if isinstance(message.author, revolt.Member):
# print(f"{message.author.name}#{message.author.discriminator} ({message.author.id}): {message.content}\n ⤷ Sent from {message.server.name} ({message.server.id})")
# else:
# print(f"{message.author.name}#{message.author.discriminator} ({message.author.id}): {message.content}\n ⤷ Sent in Direct Messages")
# await Client.process_commands(self, message)
@commands.command() @commands.command()
async def ping(self, ctx: commands.Context): async def ping(self, ctx: commands.Context):