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

Commit

Permalink
Release 0.6
Browse files Browse the repository at this point in the history
I completely rewrote the bot code. The "!type" command has been removed. Added commands "!kick", "!ban", "!clear".
  • Loading branch information
riderius committed Apr 25, 2021
1 parent fe502b4 commit d3ccc38
Showing 1 changed file with 84 additions and 89 deletions.
173 changes: 84 additions & 89 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
"""Main file the discord bot"""

import sys
import asyncio
import os
import discord
from loguru import logger
from discord.ext import commands
from settings import TOKEN
from loguru import logger

__version__ = "0.5-dev4"
__author__ = "RIDERIUS"
__version__ = "0.6"

# pylint settings:
# pylint: disable=C0301

RIDERIUS_ICON_URL = "https://cdn.discordapp.com/avatars/518031210644242433/81e47876e62fac858786b893bdd3c5b9.png"

logger.add(
"DEBUG.log",
format="{time} {level} {message}",
Expand All @@ -23,101 +21,96 @@
encoding="utf-8",
)

client = discord.Client()


# @logger.catch
# @client.event
# async def on_member_join(member):
# """This feature is only triggered if a member joins the server"""
# pass
client = commands.Bot(command_prefix="!", intents=discord.Intents.all())


@logger.catch
@client.event
async def on_ready() -> None:
"""This function log about connected account"""

async def on_ready():
"""
on_ready - This code is executed immediately after starting the bot.
"""
logger.info("We have logged in as {0.user}".format(client))
await client.change_presence(
status=discord.Status.online, activity=discord.Game("!manual | v" + __version__)
status=discord.Status.online,
activity=discord.Game(f"!manual | v{__version__} | https://discord.gg/CvswN4t"),
)


@logger.catch
@client.event
async def on_message(message) -> None:
"""This function use messages related events"""

if message.author == client.user:
return

# Command hello or hi
if message.content.startswith("!hello") or message.content.startswith("!hi"):
await message.channel.send("Hello, " + str(message.author.mention) + "!")
logger.info("Hello print by: " + str(message.author))

# Command echo
if message.content.startswith("!echo"):
await message.delete()
await message.channel.send(message.content.replace("!echo ", ""))
logger.info(
"Echo print by: "
+ str(message.author)
+ "\n Sended echo message: "
+ message.content.replace("!echo", "")
)
@client.command(pass_content=True)
async def manual(ctx):
"""!manual - displays the manual for the bot"""
author = ctx.message.author
manual = discord.Embed(
title="Bot manual",
description="""!manual - displays the manual for the bot
!echo - repeats the message
!hello - greets the caller
!clear [arg] - deletes messages, replace [arg] with the number of messages to delete
!kick - for kick user
!ban - for ban user""",
)
manual.set_author(
name="RIDERIUS",
url="https://github.com/riderius",
icon_url="https://cdn.discordapp.com/avatars/518031210644242433/81e47876e62fac858786b893bdd3c5b9.png",
)
await ctx.send(embed=manual)
logger.info("!Manual print by: " + str(author))

# Command type
if message.content.startswith("!type"):
original_message = message.content.replace("!type ", "")
logger.info(
"Type print by: "
+ str(message.author)
+ "\nOriginal message: "
+ original_message
)
number_symbol_in_message = len(original_message)
sending_message = "▒" * number_symbol_in_message
editon_message = await message.channel.send(
"Message by " + str(message.author.mention) + ": " + sending_message
)
normal_message = ""
await message.delete()
for opened_symbols in range(number_symbol_in_message):
opened_message = list(original_message)
normal_message += opened_message[opened_symbols]
sending_message = (
"Message by "
+ str(message.author.mention)
+ ": "
+ normal_message
+ "▒" * (number_symbol_in_message - opened_symbols)
)
await asyncio.sleep(0.05)
await editon_message.edit(content=sending_message)
end_message = (
"Message by " + str(message.author.mention) + ": " + normal_message
)
await editon_message.edit(content=end_message)
logger.info("End message: " + end_message)

# Command manual
if message.content.startswith("!manual"):
manual = discord.Embed(
title="Bot manual",
description="""!manual - displays the manual for the bot
!type - Encrypts the message for a while
!echo - repeats the message
!hello | !hi - greets the caller""",
)
manual.set_author(
name="RIDERIUS",
url="https://github.com/riderius",
icon_url=RIDERIUS_ICON_URL,

@logger.catch
@client.command(pass_content=True)
async def hello(ctx):
"""!hello - greets the caller"""
author = ctx.message.author
await ctx.send("Hello, " + str(author.mention) + "!")
logger.info("!Hello print by: " + str(author))


@logger.catch
@client.command(pass_content=True)
async def echo(ctx, *arg):
"""!echo - repeats the message"""
author = ctx.message.author
await ctx.channel.purge(limit=1)
await ctx.send(f'Message from {author.mention}: {" ".join(arg)}')
logger.info(
f'!Echo print by: {ctx.message.author}\nSended echo message: {" ".join(arg)}'
)


@logger.catch
@client.command(pass_content=True)
@commands.has_permissions(administrator=True)
async def clear(ctx, amount=0):
"""!clear [arg] - deletes messages, replace [arg] with the number of messages to delete."""
logger.info(f"amount = {amount}")
if amount == 0:
await ctx.send(
"Add an argument to the command. The argument is the number of messages to delete. Example command: !Clear 5. The example demonstrates a command that will delete 5 messages."
)
await message.channel.send(embed=manual)
logger.info("Manual print by: " + str(message.author))
else:
await ctx.channel.purge(limit=amount)


@client.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def kick(ctx, member: discord.Member, *, reason=None):
"""!kick - for kick user"""
await member.kick(reason=reason)
await ctx.send(f"Kick user {member.mention}. Reason {reason}")
logger.info(f"User kicked {member.mention}\nReason: {reason} \n!kick print by: {ctx.message.author}")


@client.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def ban(ctx, member: discord.Member, *, reason=None):
"""!ban - for ban user"""
await member.ban(reason=reason)
await ctx.send(f"Ban user {member.mention}. Reason {reason}")
logger.info(f"User banned {member.mention}\nReason: {reason} \n!ban print by: {ctx.message.author}")


@logger.catch
Expand All @@ -126,6 +119,8 @@ def main() -> None:

logger.info("Version bot: " + __version__)
logger.info("OS: " + sys.platform)
if sys.platform == "linux":
logger.info(f"Uname: {os.uname()}")
logger.info("Python version: " + sys.version)
logger.info("Version discord.py: " + discord.__version__)
client.run(TOKEN)
Expand Down

0 comments on commit d3ccc38

Please sign in to comment.