mirror of https://github.com/sgoudham/Enso-Bot.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
6.5 KiB
Python
189 lines
6.5 KiB
Python
5 years ago
|
import asyncio
|
||
5 years ago
|
import datetime
|
||
5 years ago
|
|
||
5 years ago
|
import discord
|
||
5 years ago
|
from decouple import config
|
||
5 years ago
|
from discord import Embed, Colour
|
||
5 years ago
|
from discord.ext import commands
|
||
5 years ago
|
from discord.ext.commands import is_owner
|
||
5 years ago
|
|
||
5 years ago
|
import settings
|
||
|
|
||
5 years ago
|
# Getting the Bot token from Environment Variables
|
||
5 years ago
|
API_TOKEN = config('DISCORD_TOKEN')
|
||
5 years ago
|
|
||
5 years ago
|
# Bot Initiation
|
||
|
client = commands.Bot( # Create a new bot
|
||
|
command_prefix="~", # Set the prefix
|
||
|
description='Ensō~Chan!', # Set a description for the bot
|
||
|
owner_id=154840866496839680) # Your unique User ID
|
||
5 years ago
|
|
||
5 years ago
|
(anime, helps, fun) = settings.extensions()
|
||
|
complete_list = anime + helps + fun
|
||
|
|
||
5 years ago
|
# Calls the cogs from the settings.py file and loads them
|
||
5 years ago
|
if __name__ == '__main__':
|
||
5 years ago
|
for ext in complete_list:
|
||
5 years ago
|
client.load_extension(ext)
|
||
|
|
||
5 years ago
|
|
||
5 years ago
|
# Bot Status on Discord
|
||
5 years ago
|
@client.event
|
||
|
async def on_ready():
|
||
5 years ago
|
# Tells me that the bot is ready and logged in
|
||
5 years ago
|
print('Bot is ready.')
|
||
5 years ago
|
|
||
|
# Sets the bots status on discord for everyone to view
|
||
5 years ago
|
await client.change_presence(activity=discord.Game(name="Feeling Pretty Good :))"))
|
||
5 years ago
|
|
||
5 years ago
|
|
||
5 years ago
|
# Bot ~Ping command in milliseconds
|
||
5 years ago
|
@client.command(name="ping", aliases=["Ping"])
|
||
5 years ago
|
@is_owner()
|
||
5 years ago
|
async def ping(ctx):
|
||
5 years ago
|
# Send the latency of the bot (ms)
|
||
5 years ago
|
await ctx.send(f'Pong! {round(client.latency * 1000)}ms')
|
||
|
|
||
5 years ago
|
|
||
5 years ago
|
# Bot event for new member joining, sending an embed introducing them to the server
|
||
5 years ago
|
@client.event
|
||
|
async def on_member_join(member):
|
||
5 years ago
|
# Set the channel id to "newpeople"
|
||
5 years ago
|
new_people = client.get_channel(669771571337887765)
|
||
5 years ago
|
# Set the channel id to "general"
|
||
5 years ago
|
general = client.get_channel(663651584399507481)
|
||
5 years ago
|
|
||
5 years ago
|
# Set the enso server icon and the welcoming gif
|
||
|
server_icon = "https://media.discordapp.net/attachments/683490529862090814/715010931620446269/image1.jpg?width=658&height=658"
|
||
|
welcome_gif = "https://cdn.discordapp.com/attachments/714671068941647933/717144047252275270/f4d7de6463d3ada02058a094fd6917ac.gif"
|
||
|
|
||
5 years ago
|
# Set up embed for the #newpeople channel
|
||
|
embed = Embed(title="\n**Welcome To Ensō!**",
|
||
|
colour=Colour(0x30e419),
|
||
|
timestamp=datetime.datetime.utcnow())
|
||
|
|
||
|
embed.set_thumbnail(url=server_icon)
|
||
|
embed.set_image(url=welcome_gif)
|
||
|
embed.add_field(
|
||
|
name="\u200b",
|
||
|
value=f"Hello {member.mention}! We hope you enjoy your stay in this server! ",
|
||
|
inline=False)
|
||
|
embed.add_field(
|
||
|
name="\u200b",
|
||
|
value=f"Be sure to check out our <#669815048658747392> channel to read the rules and <#683490529862090814> channel to get caught up with any changes! ",
|
||
|
inline=False)
|
||
|
embed.add_field(
|
||
|
name="\u200b",
|
||
|
value=f"Last but not least, feel free to go into <#669775971297132556> to introduce yourself!",
|
||
|
inline=False)
|
||
|
|
||
|
# Send embed to #newpeople
|
||
|
await new_people.send(embed=embed)
|
||
|
|
||
|
# Set hamothyID equal to my id in discord
|
||
|
hamothyID = '<@&715412394968350756>'
|
||
|
|
||
|
# String for welcoming people in the #general channel
|
||
|
general_welcome = f"Welcome to the server! {member.mention} I hope you enjoy your stay here <a:huh:676195228872474643> <a:huh:676195228872474643> " \
|
||
|
f"\nPlease go into <#722347423913213992> to choose some ping-able roles for events! " \
|
||
|
f"\nPlease ping {hamothyID} for any questions about the server and of course, the other staff members!"
|
||
|
|
||
|
# Send welcome message to #general
|
||
|
await general.send(general_welcome)
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
# Allows the bot to echo the dm's that it receives
|
||
5 years ago
|
@client.event
|
||
|
async def on_message(message):
|
||
5 years ago
|
# Making sure that the bot doesn't reply to itself
|
||
5 years ago
|
if message.author == client.user:
|
||
|
return
|
||
5 years ago
|
|
||
|
# Setting the id of myself
|
||
|
author = message.author.id
|
||
|
|
||
5 years ago
|
# Checking if the message is not sent in server
|
||
5 years ago
|
if message.guild is None:
|
||
5 years ago
|
# Checking if the owner is sending the message
|
||
5 years ago
|
if author == client.owner_id:
|
||
5 years ago
|
|
||
5 years ago
|
# Send message to #general
|
||
5 years ago
|
channel = client.get_channel(663651584399507481)
|
||
5 years ago
|
await channel.send(message.content)
|
||
5 years ago
|
|
||
5 years ago
|
else:
|
||
5 years ago
|
# Sends error message if the person is not the owner
|
||
5 years ago
|
message = await message.channel.send("Sorry, you don't have permission to echo dms!")
|
||
|
|
||
|
# Let the user read the message for 2.5 seconds
|
||
|
await asyncio.sleep(2.5)
|
||
|
# Delete the message
|
||
|
await message.delete()
|
||
5 years ago
|
|
||
5 years ago
|
await client.process_commands(message)
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
# Bot Event for handling all errors within discord.commands
|
||
5 years ago
|
@client.event
|
||
5 years ago
|
async def on_command_error(ctx, args2):
|
||
5 years ago
|
# if the user did not specify an user
|
||
5 years ago
|
if isinstance(args2, commands.MissingRequiredArgument):
|
||
|
await on_command_missing_user(ctx)
|
||
5 years ago
|
# if the user has spammed a command and invoked a cooldown
|
||
5 years ago
|
elif isinstance(args2, commands.CommandOnCooldown):
|
||
|
await on_command_cooldown(ctx, args2)
|
||
5 years ago
|
# if the user does not the correct permissions to call a command
|
||
5 years ago
|
elif isinstance(args2, commands.CheckFailure):
|
||
|
await on_command_permission(ctx)
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
# Async def for handling cooldown error/permission errors
|
||
|
async def on_command_cooldown(ctx, error):
|
||
|
# Send an error message to the user telling them that the command is on cooldown
|
||
|
message = await ctx.send(f'That command is on cooldown. Try again in {error.retry_after:,.2f} seconds.')
|
||
5 years ago
|
|
||
5 years ago
|
# Let the User read the message for 2.5 seconds
|
||
5 years ago
|
await asyncio.sleep(2.5)
|
||
|
# Delete the message
|
||
|
await message.delete()
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
# Async def for handling permission errors
|
||
|
async def on_command_permission(ctx):
|
||
|
# Send an error message to the user saying that they don't have permission to use this command
|
||
|
message = await ctx.send("Uh oh! You don't have permission to use this command!")
|
||
|
|
||
5 years ago
|
# Let the user read the message for 2.5 seconds
|
||
|
await asyncio.sleep(2.5)
|
||
5 years ago
|
# Delete the message
|
||
|
await message.delete()
|
||
|
|
||
|
|
||
|
async def on_command_missing_user(ctx):
|
||
|
# Send an error message to the user saying that an argument is missing
|
||
|
message = await ctx.send("Uh oh! Couldn't find anyone to mention! Try again!")
|
||
|
|
||
5 years ago
|
# Let the user read the message for 2.5 seconds
|
||
|
await asyncio.sleep(2.5)
|
||
5 years ago
|
# Delete the message
|
||
|
await message.delete()
|
||
5 years ago
|
|
||
5 years ago
|
|
||
5 years ago
|
# Run the bot, allowing it to come online
|
||
5 years ago
|
try:
|
||
|
client.run(API_TOKEN)
|
||
|
except discord.errors.LoginFailure as e:
|
||
|
print("Login unsuccessful.")
|
||
5 years ago
|
|
||
5 years ago
|
"""
|
||
5 years ago
|
def write_to_dm_file(time, author, content):
|
||
|
with open('images/logs/dm-logs.txt', mode='a') as dm_logs_file:
|
||
|
dm_logs_file.write(f"{time}: {author}: {content}")
|
||
|
|
||
|
# File Writing Variables
|
||
|
time = message.created_at
|
||
|
msg_time = time.strftime('%Y-%m-%dT%H:%M:%S')
|
||
|
msg_author = message.author
|
||
|
msg_content = message.content
|
||
5 years ago
|
"""
|