171 lines
6.1 KiB
Python
171 lines
6.1 KiB
Python
#Main.py
|
|
import os
|
|
import sys
|
|
import logging
|
|
import asyncio
|
|
from time import sleep
|
|
import discord
|
|
import platform
|
|
import json
|
|
import socket
|
|
import shutil
|
|
import time
|
|
#from python-dotenv import load_dotenv
|
|
from discord.ext import commands
|
|
from discord.ext.commands import is_owner
|
|
|
|
# Discord Xeno Bot in Python, Proj started 4/30/22
|
|
botversion = "0.0.2"
|
|
botbuilddate = "06/14/23"
|
|
|
|
# Load in main settings json
|
|
with open("./settings.json", "r") as configjsonFile:
|
|
botconfig = json.load(configjsonFile)
|
|
TOKEN = botconfig["TOKEN"]
|
|
OWNERID = botconfig["OWNER_ID"]
|
|
STATUS = botconfig["ACTIVITY"]
|
|
BOTLOGCHNL = botconfig["botlogchannel"]
|
|
|
|
|
|
initcurtime = time.localtime()
|
|
curtime = (f'{initcurtime.tm_hour}{initcurtime.tm_min}{initcurtime.tm_sec}')
|
|
curdate = (f'{initcurtime.tm_year}{initcurtime.tm_mon}{initcurtime.tm_mday}')
|
|
|
|
# Configure logging
|
|
logging.basicConfig(filename=f"PythonXeno_{curdate}.log",
|
|
format='%(asctime)s %(levelname)s %(message)s',
|
|
filemode='a')
|
|
log = logging.getLogger()
|
|
log.setLevel(logging.DEBUG)
|
|
logging.getLogger("urllib3").setLevel(logging.WARNING) # fuck urllib3 for making excessive logs in TranstarArchive
|
|
logging.getLogger("discord").setLevel(logging.WARNING) # wtf discord making the log file massive with shit
|
|
|
|
#load_dotenv()
|
|
#client = discord.Client()
|
|
#Defining bot v
|
|
bot = commands.Bot(command_prefix='i!',intents=discord.Intents.all())
|
|
|
|
print (f'Xeno Discord PY Bot- Version {botversion}')
|
|
|
|
print (f'Built on VSCode. Created by iRaven.')
|
|
print (f'Currently running on these specifications:')
|
|
print (f'{platform.machine()} - {platform.architecture()} {platform.processor()}')
|
|
print (f'Connecting to Discord...')
|
|
|
|
# Critical methods
|
|
|
|
## Loading any cogs found (CRITICAL)
|
|
async def botPlugins(eaction):
|
|
if eaction == "load":
|
|
print('Now loading any cogs in /cogs directory....')
|
|
for filename in os.listdir("./cogs"):
|
|
if filename.endswith(".py"):
|
|
await bot.load_extension(f"cogs.{filename[:-3]}") # :-3
|
|
print('Extensions were loaded c:')
|
|
elif eaction == "unload":
|
|
print('Now unloading any cogs in /cogs directory....')
|
|
for filename in os.listdir("./cogs"):
|
|
if filename.endswith(".py"):
|
|
await bot.unload_extension(f"cogs.{filename[:-3]}") # :-3
|
|
|
|
## Bot logging message to #xeno-bot-log
|
|
async def botLog(logmsg):
|
|
logchnl = bot.get_channel(761854845283860531)
|
|
print(f'Sent message to {logchnl.name}:{logmsg}')
|
|
# await logchnl.send(f'test :3')
|
|
await logchnl.send(f'{logmsg}')
|
|
|
|
## idk what the fuck this is
|
|
def commandLog(cmdnm):
|
|
print(f'Command was used: {cmdnm}')
|
|
|
|
@bot.event
|
|
async def on_ready():
|
|
print(f'{bot.user} is succesfully logged in with the current token.')
|
|
await bot.change_presence(activity=discord.Game(name=STATUS))
|
|
await botPlugins("load")
|
|
guild_count = 0
|
|
print ("Looking for servers:")
|
|
for guild in bot.guilds:
|
|
guild_count = guild_count + 1
|
|
print(f"Server found- {guild.id} / {guild.name}")
|
|
print("Currently in " + str(guild_count) + " servers")
|
|
print(f'Current ping to Discord servers: {bot.latency * 1000} ms')
|
|
synced = await bot.tree.sync()
|
|
print(f"{len(synced)} slash commands were synced successfully")
|
|
await botLog(f"Xeno is online- started {curdate} {curtime}")
|
|
|
|
# commands that always exist (basic func)
|
|
@bot.command(name='test')
|
|
async def test(ctx, arg):
|
|
await ctx.channel.send(f'Hewwo {arg} :3')
|
|
|
|
@bot.command(name='ping')
|
|
async def ping(ctx):
|
|
print(f'Manual ping sent-Current ping to Discord servers: {bot.latency * 1000} ms')
|
|
await ctx.channel.send(f'Tink! {bot.latency * 1000} ms')
|
|
|
|
@bot.command(name='hi')
|
|
async def ping(ctx):
|
|
await ctx.channel.send(f'Hewwo {ctx.message.author.name} :3')
|
|
|
|
# Bot Administration Commands below
|
|
@bot.command(name='shutdown')
|
|
@is_owner()
|
|
async def botshutdown(ctx):
|
|
print("Bot owner user requested bot shutdown NOW!")
|
|
print("The system is going down NOW!")
|
|
await ctx.reply(f"<a:loading_yt:1119526286621159555> The system is going down NOW! - Shutting down...")
|
|
bot.close() # i guess?
|
|
await botPlugins("unload") # unloads any cogs
|
|
print("Bot shutdown time has arrived")
|
|
await exit()
|
|
|
|
@bot.command(name='reloadexts')
|
|
@is_owner()
|
|
async def reloadcogs(ctx):
|
|
print("Bot owner user requested to reload all cogs")
|
|
await ctx.reply(f"<a:loading_yt:1119526286621159555> Reloading all extensions...")
|
|
print("Reloading all cogs now")
|
|
await botPlugins("unload")
|
|
time.sleep(1) # wait a second
|
|
await botPlugins("load")
|
|
await ctx.reply("Extensions reloaded successfully.")
|
|
|
|
# Slash Commands (more for testing as of 2023/06)
|
|
|
|
@bot.tree.command(name= "slashdebug", description="Tests slash command functionality")
|
|
async def slashdebug(interaction: discord.Interaction):
|
|
await interaction.response.send_message(f"You are super neat :)")
|
|
|
|
@bot.command(name='about')
|
|
async def aboutbot(ctx):
|
|
embed=discord.Embed(title="Xeno Bot Information", description="you're a cute pone :3")
|
|
embed.add_field(name='XenoBot Version',value=f'{botversion}',inline=True)
|
|
embed.add_field(name='Build Date',value=f'{botbuilddate}',inline=True)
|
|
embed.add_field(name='Python Version',value=f'{platform.python_version()}')
|
|
embed.add_field(name='Originally Created',value='September 2018')
|
|
embed.add_field(name='Code Rewritten in JS',value='December 2018')
|
|
embed.add_field(name='Current Code Rewritten in Python (from scratch!)',value='May 2022')
|
|
embed.add_field(name='Bot Owner',value='iRaven (Special Kudos to ItzGabe25 for most of the js code, in use until June 2023)')
|
|
embed.set_thumbnail(url="https://iravenhome.net/siteimg/xenobot.png")
|
|
await ctx.send(embed=embed)
|
|
|
|
|
|
# This stuff right here breaks everything oops lmao
|
|
#@bot.event
|
|
#async def on_message(message):
|
|
# if message.content == "test":
|
|
# await message.channel.send("helo")
|
|
# if message.content == "wubs":
|
|
# await message.channel.send("wubs?! where?!")
|
|
|
|
@bot.listen('on_message')
|
|
async def wordresponder(message):
|
|
if message.content == "test":
|
|
await message.channel.send("helo")
|
|
if message.content == "wubs":
|
|
await message.channel.send("wubs?! where?!")
|
|
|
|
|
|
bot.run(TOKEN) |