Skip to content

Commit

Permalink
Merge pull request #70 from shndowbots/patch-1
Browse files Browse the repository at this point in the history
Add new owner only commands - (un)sync & (re)(un)load
  • Loading branch information
kkrypt0nn authored Sep 30, 2022
2 parents 70890d6 + c3cfb0a commit 2d0f342
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 52 deletions.
6 changes: 6 additions & 0 deletions UPDATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Here is the list of all the updates that I made on this template.

### Vesion 5.2 (30 September 2022)

* Added `load`, `reload` and `unload` commands.
* Added `sync` and `unsync` commands.
* Code refactoring and cleanup.

### Version 5.1 (12 September 2022)

* Added the `help` command once again
Expand Down
18 changes: 9 additions & 9 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 5.1
Version: 5.2
"""

import asyncio
Expand All @@ -13,14 +13,12 @@
import random
import sqlite3
import sys

from contextlib import closing

import discord
from discord import Interaction
from discord.ext import tasks, commands
from discord.ext.commands import Bot
from discord.ext.commands import Context
from discord.ext import commands, tasks
from discord.ext.commands import Bot, Context

import exceptions

Expand Down Expand Up @@ -73,7 +71,8 @@
"""
# intents.message_content = True

bot = Bot(command_prefix=commands.when_mentioned_or(config["prefix"]), intents=intents, help_command=None)
bot = Bot(command_prefix=commands.when_mentioned_or(
config["prefix"]), intents=intents, help_command=None)


def init_db():
Expand All @@ -97,6 +96,7 @@ def connect_db():
bot.config = config
bot.db = connect_db()


@bot.event
async def on_ready() -> None:
"""
Expand All @@ -108,7 +108,6 @@ async def on_ready() -> None:
print(f"Running on: {platform.system()} {platform.release()} ({os.name})")
print("-------------------")
status_task.start()
await bot.tree.sync()


@tasks.loop(minutes=1.0)
Expand Down Expand Up @@ -145,7 +144,8 @@ async def on_command_completion(context: Context) -> None:
print(
f"Executed {executed_command} command in {context.guild.name} (ID: {context.guild.id}) by {context.author} (ID: {context.author.id})")
else:
print(f"Executed {executed_command} command by {context.author} (ID: {context.author.id}) in DMs")
print(
f"Executed {executed_command} command by {context.author} (ID: {context.author.id}) in DMs")


@bot.event
Expand Down Expand Up @@ -222,4 +222,4 @@ async def load_cogs() -> None:

init_db()
asyncio.run(load_cogs())
bot.run(config["token"])
bot.run(config["token"])
15 changes: 8 additions & 7 deletions cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 5.1
Version: 5.2
"""

import random
Expand All @@ -13,7 +13,6 @@
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context

from helpers import checks


Expand Down Expand Up @@ -66,7 +65,10 @@ async def callback(self, interaction: discord.Interaction):
bot_choice_index = choices[bot_choice]

result_embed = discord.Embed(color=0x9C84EF)
result_embed.set_author(name=interaction.user.name, icon_url=interaction.user.avatar.url)
result_embed.set_author(
name=interaction.user.name,
icon_url=interaction.user.avatar.url
)

if user_choice_index == bot_choice_index:
result_embed.description = f"**That's a draw!**\nYou've chosen {user_choice} and I've chosen {bot_choice}."
Expand Down Expand Up @@ -104,7 +106,7 @@ def __init__(self, bot):
async def randomfact(self, context: Context) -> None:
"""
Get a random fact.
:param context: The hybrid command context.
"""
# This will prevent your bot from stopping everything when doing a web request - see: https://discordpy.readthedocs.io/en/stable/faq.html#how-do-i-make-a-web-request
Expand Down Expand Up @@ -132,7 +134,7 @@ async def randomfact(self, context: Context) -> None:
async def coinflip(self, context: Context) -> None:
"""
Make a coin flip, but give your bet before.
:param context: The hybrid command context.
"""
buttons = Choice()
Expand All @@ -143,7 +145,6 @@ async def coinflip(self, context: Context) -> None:
message = await context.send(embed=embed, view=buttons)
await buttons.wait() # We wait for the user to click a button.
result = random.choice(["heads", "tails"])
print(buttons.value)
if buttons.value == result:
embed = discord.Embed(
description=f"Correct! You guessed `{buttons.value}` and I flipped the coin to `{result}`.",
Expand All @@ -164,7 +165,7 @@ async def coinflip(self, context: Context) -> None:
async def rock_paper_scissors(self, context: Context) -> None:
"""
Play the rock paper scissors game against the bot.
:param context: The hybrid command context.
"""
view = RockPaperScissorsView()
Expand Down
2 changes: 1 addition & 1 deletion cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 5.1
Version: 5.2
"""

import platform
Expand Down
15 changes: 7 additions & 8 deletions cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
Description:
This is a template to create your own discord bot in python.
Version: 5.1
Version: 5.2
"""

import discord
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context

from helpers import checks
from helpers import db_manager
from helpers import checks, db_manager


class Moderation(commands.Cog, name="moderation"):
Expand Down Expand Up @@ -112,7 +110,7 @@ async def nick(self, context: Context, user: discord.User, nickname: str = None)
async def ban(self, context: Context, user: discord.User, reason: str = "Not specified") -> None:
"""
Bans a user from the server.
:param context: The hybrid command context.
:param user: The user that should be banned from the server.
:param reason: The reason for the ban. Default is "Not specified".
Expand Down Expand Up @@ -176,7 +174,8 @@ async def warning_add(self, context: Context, user: discord.User, reason: str =
:param reason: The reason for the warn. Default is "Not specified".
"""
member = context.guild.get_member(user.id) or await context.guild.fetch_member(user.id)
total = db_manager.add_warn(user.id, context.guild.id, context.author.id, reason)
total = db_manager.add_warn(
user.id, context.guild.id, context.author.id, reason)
embed = discord.Embed(
title="User Warned!",
description=f"**{member}** was warned by **{context.author}**!\nTotal warns for this user: {total}",
Expand Down Expand Up @@ -227,13 +226,13 @@ async def warning_add(self, context: Context, user: discord.User, warn_id: int)
async def warning_list(self, context: Context, user: discord.User):
"""
Shows the warnings of a user in the server.
:param context: The hybrid command context.
:param user: The user you want to get the warnings of.
"""
warnings_list = db_manager.get_warnings(user.id, context.guild.id)
embed = discord.Embed(
title = f"Warnings of {user}",
title=f"Warnings of {user}",
color=0x9C84EF
)
description = ""
Expand Down
Loading

0 comments on commit 2d0f342

Please sign in to comment.