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

Commit

Permalink
Merge pull request #19 from r-liner/develop
Browse files Browse the repository at this point in the history
v0.8.0
  • Loading branch information
liner-exe authored Feb 14, 2024
2 parents 794c9c3 + 5ba1661 commit ccf3d37
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 30 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Python cache / Optimized files
__pycache__/
*.py[cod]

# Environment
.env
.venv
env/
venv/
ENV/

# PyCharm
.idea/

# Vs Code
.vscode/

# Config files / Databases
*.ini
*.db

# Logs
*.log
logs/
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
# Discord Commands Bot - Changelog

## [v0.8.0](https://github.com/r-liner/discord-commands-bot/releases/tag/v0.8.0) (2024-02-14)

[Full Changelog](https://github.com/r-liner/discord-commands-bot/compare/v0.7.8...v0.8.0)

### Features
- Slash commands migration!
- **main.py:** added dependency checker, added update notifier
- **cogs/fun.py@Fun:weather:** command is inactive if no openweather token

### New Files
- cogs/utils/
- __init\__.py
- decorators.py
- dependecies.py
- github.py
- version.py
- .gitignore

### Documentation
- **cogs/\*.py:** added docstrings to all functions
- **version.txt:** version bumped to 0.8.0
- **README.md:** fixed typo

### Chore
- **main.py:** fixed typo
- **requirements.txt:** updated dependencies

## [v0.7.8](https://github.com/r-liner/discord-commands-bot/releases/tag/v0.7.8) (2024-02-13)

[Full Changelog](https://github.com/r-liner/discord-commands-bot/compare/v0.7.7...v0.7.8)

### Documentation
- **README.md:** fixed typos. Added link to changelog
- **config.yml:** added emoji to `name`
- **version.txt:** version bumber to 0.7.8
- **CHANGELOG.md:** added v0.7.7 release notes, changelog adjusted

### Tweak
- **start_win.bat:** compatibility with new Python version. Minor correction

### Chore
- **config.ini.sample:** removed useless info

### Bugfix
- **main.py:** moved universal exception handling to the end of the try-except block




## [v0.7.7](https://github.com/r-liner/discord-commands-bot/releases/tag/v0.7.7) (2024-02-12)

[Full Changelog](https://github.com/r-liner/discord-commands-bot/compare/v0.7.6...v0.7.7)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pip install -r requirements.txt
```sh
git clone https://github.com/r-liner/discord-commands-bot
```
3. Launch `setup.py` and complete setup procces.
3. Launch `setup.py` and complete setup process.
4. Done. Now you can launch the bot.

## Launch
Expand Down
48 changes: 37 additions & 11 deletions cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,52 @@ def __init__(self, client):

@application_checks.is_owner()
@nextcord.slash_command()
async def change_nickname(self, interaction, name: str = nextcord.SlashOption(default=None)):
async def change_nickname(self, interaction, nickname: str = nextcord.SlashOption(default=None, required=False)):
"""
[ADMIN] Change bot nickname.
Parameters
----------
interaction: Interaction
nickname: str
Enter a new bot nickname.
"""
await interaction.guild.me.edit(nick=name)
await interaction.guild.me.edit(nick=nickname)

if name:
return await interaction.send(f"Display name of bot has changed on **{name}**")
if nickname:
return await interaction.send(f"Display name of bot has changed on **{nickname}**")

elif name is None:
elif nickname is None:
return await interaction.send(f"Nickname has cleared")

@application_checks.is_owner()
@nextcord.slash_command(guild_ids=(admin_guilds,))
async def change_username(self, interaction, name: str = nextcord.SlashOption(default=None)):
async def change_username(self, interaction, username: str = nextcord.SlashOption(default=None, required=False)):
"""
[ADMIN] Change bot username.
Parameters
----------
interaction: Interaction
username: str
Enter a new bot username.
"""
await self.client.user.edit(username=name)
await interaction.send(f"Username of bot has changed on **{name}**")
await self.client.user.edit(username=username)
await interaction.send(f"Username of bot has changed on **{username}**")

@application_checks.is_owner()
@nextcord.slash_command()
async def direct_message(self, interaction, user: nextcord.User, message: str):
"""
[ADMIN] Send direct message to selected user.
Parameters
----------
interaction: Interaction
user: nextcord.User
Choose an user to dm.
message: str
Enter a message to send.
"""
try:
await user.send(message)
Expand All @@ -59,13 +79,19 @@ async def shutdown(self, interaction):

@application_checks.is_owner()
@nextcord.slash_command(guild_ids=(admin_guilds,))
async def eval(self, interaction, content):
async def eval(self, interaction, expression: str):
"""
[ADMIN] Evaluates a Python expression.
Parameters
----------
interaction: Interaction
expression: str
Enter an expression to evaluate.
"""
try:
embed = nextcord.Embed(description=content)
embed.add_field(name="Result", value=eval(content))
embed = nextcord.Embed(description=expression)
embed.add_field(name="Result", value=eval(expression))
await interaction.send(embed=embed)

except SyntaxError:
Expand Down
2 changes: 1 addition & 1 deletion cogs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def on_command_error(self, ctx, err: Exception):

@commands.Cog.listener()
async def on_application_command_error(self, interaction, error: Exception):
embed = nextcord.Embed(title="Error", colour=nextcord.Colors.light_red)
embed = nextcord.Embed(title="Error", colour=nextcord.Color.red)

if isinstance(error, application_checks.errors.ApplicationMissingPermissions):
embed.description = "You do not have permissions to perform this action."
Expand Down
39 changes: 31 additions & 8 deletions cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import math
import configparser

from utils.decorators import is_weather_active
from .utils import is_weather_active

config = configparser.ConfigParser()
config.read("config.ini")
Expand Down Expand Up @@ -79,6 +79,12 @@ async def password(self, interaction, length: int = nextcord.SlashOption(min_val
default=8)):
"""
Random password generator.
Parameters
----------
interaction: Interaction
length: int
Enter password length.
"""
password = ''.join(
random.sample(string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation,
Expand All @@ -103,22 +109,33 @@ async def coin(self, interaction):
await interaction.send(embed=embed)

@nextcord.slash_command()
async def say(self, interaction, sentence):
async def say(self, interaction, text: str):
"""
Say message as the bot.
Parameters
----------
interaction: Interaction
text: str
Enter a text to say.
"""
embed = nextcord.Embed(
description=f'{sentence}',
description=f'{text}',
)
await interaction.send(embed=embed)
await interaction.message.delete()

@nextcord.slash_command()
async def reverse(self, interaction, sentence):
async def reverse(self, interaction, text: str):
"""
Reverse entered message.
Parameters
----------
interaction: Interaction
text: str
Enter a text to reverse.
"""
await interaction.send(f"{sentence[::-1]}")
await interaction.send(f"{text[::-1]}")

@nextcord.slash_command()
async def random(self, interaction,
Expand All @@ -137,11 +154,17 @@ async def random(self, interaction,
embed.add_field(name="Result", value=f"{random.randint(first_num, second_num)}")
await interaction.send(embed=embed)

@is_weather_active()
@is_weather_active
@nextcord.slash_command()
async def weather(self, interaction, _city):
async def weather(self, interaction, _city = nextcord.SlashOption(name="city")):
"""
Get a weather forecast in certain city.
Parameters
----------
interaction: Interaction
_city: str
Enter a city to get weather forecast.
"""
try:
ow_token = config["bot"]["openweather_token"]
Expand Down
41 changes: 40 additions & 1 deletion cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ async def unlock(self, interaction):
async def ban(self, interaction, member: Member, reason: str = nextcord.SlashOption(default="No reason.")):
"""
Ban a certain user.
Parameters
----------
interaction: Interaction
member: int
Choose an user.
reason: str
Type a reason.
"""
embed = nextcord.Embed(title='Ban', colour=nextcord.Colors.light_red)

Expand All @@ -73,7 +81,18 @@ async def ban(self, interaction, member: Member, reason: str = nextcord.SlashOpt

@application_checks.has_permissions(administrator=True)
@nextcord.slash_command()
async def unban(self, interaction, member, reason: str = nextcord.SlashOption(default="No reason.")):
async def unban(self, interaction, member: nextcord.Member, reason: str = nextcord.SlashOption(default="No reason.")):
"""
Ban a certain user.
Parameters
----------
interaction: Interaction
member: nextcord.Member
Choose an user.
reason: str
Type a reason.
"""
banned_users = await interaction.guild.fetch_ban(user=member)

embed = nextcord.Embed(title='Unban')
Expand Down Expand Up @@ -109,6 +128,17 @@ async def unban(self, interaction, member, reason: str = nextcord.SlashOption(de
@application_checks.has_permissions(kick_members=True)
@nextcord.slash_command()
async def kick(self, interaction, member: nextcord.Member, reason: str = nextcord.SlashOption(default="No reason.")):
"""
Kick an user.
Parameters
----------
interaction: Interaction
member: nextcord.Member
Choose an user.
reason: str
Type a reason.
"""
embed = nextcord.Embed(title='Kick')

if interaction.user.id == member.id:
Expand Down Expand Up @@ -136,6 +166,15 @@ async def kick(self, interaction, member: nextcord.Member, reason: str = nextcor
@application_checks.has_permissions(manage_messages=True)
@nextcord.slash_command()
async def clear(self, interaction, amount: int = nextcord.SlashOption(min_value=1, max_value=100)):
"""
Kick an user.
Parameters
----------
interaction: Interaction
member: int
Type a count of messages to delete.
"""
deleted = await interaction.channel.purge(limit=amount)

msg = await interaction.send(f'Messages deleted: **{len(deleted)}**')
Expand Down
3 changes: 2 additions & 1 deletion cogs/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .dependecies import *
from .decorators import *
from .decorators import *
from .github import *
21 changes: 21 additions & 0 deletions cogs/utils/github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import requests
from bs4 import BeautifulSoup

def get_latest():
response = requests.get("https://raw.githubusercontent.com/r-liner/discord-commands-bot/master/version.txt")
return response.text

def check_for_updates(version):
latest = get_latest()
if latest > version:
return True

return False

def changelog():
latest = get_latest()
response = requests.get(f"https://github.com/r-liner/discord-commands-bot/releases/tag/v{latest}")
soup = BeautifulSoup(response.text, "html.parser")
_changelog = soup.find("div", class_="markdown-body my-3").get_text()

return _changelog
3 changes: 3 additions & 0 deletions cogs/utils/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def get():
with open("version.txt", "r", encoding="utf-8") as file:
return file.read()
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import sys
import configparser
from .cogs.utils import dependecies
from cogs.utils import dependecies, github, version

intents = nextcord.Intents.all()

Expand All @@ -17,6 +17,11 @@

dependecies.check_installed()

if github.check_for_updates(version.get()):
latest = github.get_latest()
print(f"[GITHUB]: New update available: v{latest}")
print(f"CHANGELOG:\n-----------\n{github.changelog()}-----------")

@client.event
async def on_ready():
await client.change_presence(activity=nextcord.Activity(type=nextcord.ActivityType.watching, name="bot status"))
Expand Down
Loading

0 comments on commit ccf3d37

Please sign in to comment.