Create disc.py
This commit is contained in:
parent
69189ae5f1
commit
d960a5a9fc
1 changed files with 162 additions and 0 deletions
162
disc.py
Normal file
162
disc.py
Normal file
|
@ -0,0 +1,162 @@
|
|||
# Colors
|
||||
BLACK = '\033[30m'
|
||||
RED = '\033[31m'
|
||||
GREEN = '\033[32m'
|
||||
YELLOW = '\033[33m' # orange on some systems
|
||||
BLUE = '\033[34m'
|
||||
MAGENTA = '\033[35m'
|
||||
CYAN = '\033[36m'
|
||||
LIGHT_GRAY = '\033[37m'
|
||||
DARK_GRAY = '\033[90m'
|
||||
BRIGHT_RED = '\033[91m'
|
||||
BRIGHT_GREEN = '\033[92m'
|
||||
BRIGHT_YELLOW = '\033[93m'
|
||||
BRIGHT_BLUE = '\033[94m'
|
||||
BRIGHT_MAGENTA = '\033[95m'
|
||||
BRIGHT_CYAN = '\033[96m'
|
||||
WHITE = '\033[97m'
|
||||
RESET = '\033[0m'
|
||||
import discord
|
||||
import traceback
|
||||
from time import sleep
|
||||
from requests import get
|
||||
from random import randint, choice
|
||||
import os
|
||||
import sys
|
||||
import platform
|
||||
import distro
|
||||
import subprocess
|
||||
from duckduckgo_search import DDGS
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.members = True
|
||||
client = discord.Client(intents=intents)
|
||||
# Help document
|
||||
documentation = """$help - Shows this message.
|
||||
$ping - Test if bot is online.
|
||||
$version - Get version of SweeBot and the system it's running on
|
||||
$whoami - Gets your user ID
|
||||
$perms - Gets your permissions
|
||||
"""
|
||||
meows = ['Meow!', 'Nyaa~', 'Mrow.', 'Prr! :3', 'Hiss!', "Mrrp?", "Mreow.", "!woeM", "3: !rrP", "!ssiH", "~aayN", "Mew!", "Moew!"]
|
||||
version = "0.0.1r1"
|
||||
# user permissions
|
||||
def getperms(userID):
|
||||
if not os.path.isfile(str(userID)):
|
||||
open(str(userID),'w').write("")
|
||||
return []
|
||||
else:
|
||||
if open(str(userID)).read().replace("\n", "").split(",") == ['']:
|
||||
return []
|
||||
return open(str(userID)).read().replace("\n", "").split(",")
|
||||
# emoticons
|
||||
success = "<:sweebotsuccess:1265430815664242709>"
|
||||
unknown = "<:sweebotunknown:1265430817207750668>"
|
||||
fail = "<:sweebotfail:1265430820022128811>"
|
||||
loading = "<:sweebotloading:1265430823843139674>"
|
||||
# Client itself
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print('[' + GREEN + 'OK' + RESET + '] Ready')
|
||||
await client.change_presence(activity=discord.Activity(name="$help", type=discord.ActivityType.playing))
|
||||
|
||||
@client.event
|
||||
async def on_message(message):
|
||||
if message.author.name != client.user.name:
|
||||
if message.content == "":
|
||||
return
|
||||
if message.author == None:
|
||||
print(YELLOW + "Gil ("+message.channel.name+"@"+message.guild.name+")> "+RESET+message.content)
|
||||
else:
|
||||
print(YELLOW + "<"+message.author.name+" ("+message.channel.name+"@"+message.guild.name+")> "+RESET+message.content)
|
||||
if message.author.name == client.user.name or message.author.bot:
|
||||
return
|
||||
if message.content[0] == "$":
|
||||
try:
|
||||
command=message.content[1:].split(" ")
|
||||
if command[0] == "help":
|
||||
await message.reply(embed=discord.Embed(title=success + " SweeBot usage:",description=documentation))
|
||||
print("[" + GREEN + "OK" + RESET + "] '$help' executed successfully.")
|
||||
elif command[0] == "ping":
|
||||
if randint(0,2) == 1:
|
||||
print("[" + MAGENTA + "DBG" + RESET + "] Pnog easter egg.")
|
||||
mess = await message.reply(embed=discord.Embed(title=success + " Command complete.",description="Pnog."))
|
||||
else:
|
||||
mess = await message.reply(embed=discord.Embed(title=success + " Command complete.",description="Pong."))
|
||||
print("[" + GREEN + "OK" + RESET + "] '$ping' executed successfully.")
|
||||
elif command[0] == "version":
|
||||
if platform.system() == "Windows":
|
||||
print("[" + MAGENTA + "DBG" + RESET + "] Host runs Windows.")
|
||||
mess = await message.reply(embed=discord.Embed(title="SweeBot for Discord " + version +" running on:",description="* " + platform.node() + "\n* " + platform.system() + " " + platform.release() + " Version " + platform.version() + "\n* Discord.py version " + discord.__version__ + "\n* Python " + sys.version.split(" ")[0]))
|
||||
else:
|
||||
print("[" + MAGENTA + "DBG" + RESET + "] Host runs Linux.")
|
||||
mess = await message.reply(embed=discord.Embed(title="SweeBot for Discord " + version +" running on:",description="* " + platform.node() + "\n" + "* " + distro.name() + " " + distro.version() + " " + distro.codename() + "\n* Discord.py version " + discord.__version__ + "\n* Python " + sys.version.split(" ")[0]))
|
||||
print("[" + GREEN + "OK" + RESET + "] '$version' executed successfully.")
|
||||
elif command[0] == "restart":
|
||||
if "restart" in getperms(message.author.id) or "full" in getperms(message.author.id):
|
||||
mess = await message.reply(embed=discord.Embed(title=success + " Command complete.",description="Restarting bot..."))
|
||||
print("[" + BLUE + "..." + RESET + "] Restarting script... (initiated by " + message.author.name + ")")
|
||||
if os.path.isfile("/home/swee/.config/systemd/user/disc.service"):
|
||||
os.system("systemctl --user restart disc.service")
|
||||
else:
|
||||
subprocess.Popen(["py"] + sys.argv)
|
||||
exit()
|
||||
else:
|
||||
mess = await message.reply(embed=discord.Embed(title=fail + " Permission denied."))
|
||||
print("[" + RED + "FAIL" + RESET + "] Not restarting script, Permission Denied for " + message.author.name)
|
||||
elif command[0] == "whoami":
|
||||
if getperms(message.author.id) != []:
|
||||
mess = await message.reply(embed=discord.Embed(title=success + " Command complete.",description="UserID: "+str(message.author.id)+"\n:warning: Your User ID has permissions, use `$perms` to see"))
|
||||
else:
|
||||
mess = await message.reply(embed=discord.Embed(title=success + " Command complete.",description="UserID: "+str(message.author.id)))
|
||||
print("[" + GREEN + "OK" + RESET + "] '$whoami' executed successfully.")
|
||||
elif command[0] == "perms":
|
||||
if getperms(message.author.id) != []:
|
||||
mess = await message.reply(embed=discord.Embed(title=success + " Command complete.",description="`"+",".join(getperms(message.author.id))+"`"))
|
||||
else:
|
||||
mess = await message.reply(embed=discord.Embed(title=success + " Command complete.",description=":question: No permissions"))
|
||||
print("[" + GREEN + "OK" + RESET + "] '$perms' executed successfully.")
|
||||
elif command[0] == "meow":
|
||||
mess = await message.reply(embed=discord.Embed(title=choice(meows)))
|
||||
print("[" + GREEN + "OK" + RESET + "] '$meow' executed successfully.")
|
||||
elif command[0] == "figlet":
|
||||
os.system("figlet " + " ".join(command[1:]) + " > temp")
|
||||
mess = await message.reply("```\n" + open("temp").read() + "\n```")
|
||||
print("[" + GREEN + "OK" + RESET + "] '$figlet' executed successfully.")
|
||||
elif command[0] == "error":
|
||||
raise SystemError("Test Error for SweeBot")
|
||||
elif command[0] == "search":
|
||||
request = []
|
||||
while request == []:
|
||||
request = DDGS().text(" ".join(command[1:]))
|
||||
result = []
|
||||
print(request)
|
||||
for i in request:
|
||||
if len(result) != 9:
|
||||
result.append("")
|
||||
h = len(result) - 1
|
||||
result[h] += "### [" + i['title'] + '](' + i['href'] + ")\n"
|
||||
result[h] += "" + i['href']
|
||||
result[h] += "\n" + i['body'] + "\n\n"
|
||||
else:
|
||||
break
|
||||
result.append("Please check out [UnnamedSearchEngine](https://swee.pythonanywhere.com/use) btw, it's a very lightweight and private search engine.")
|
||||
print(result)
|
||||
embeds = []
|
||||
for i in result:
|
||||
embeds.append(discord.Embed(description=i))
|
||||
await message.reply("Search results:" ,embeds=embeds)
|
||||
print("[" + GREEN + "OK" + RESET + "] '$search' executed successfully.")
|
||||
else:
|
||||
mess = await message.reply(embed=discord.Embed(title=unknown + " Command not found."))
|
||||
|
||||
|
||||
except Exception as ex:
|
||||
mess = await message.reply(embed=discord.Embed(title=fail + " Command failed!",description=traceback.format_exc()))
|
||||
print("[" + RED + "FAIL" + RESET + "] Command failed, check chat for traceback.")
|
||||
else:
|
||||
print("[" + MAGENTA + "DBG" + RESET + "] No triggers in message, ignoring...")
|
||||
try:
|
||||
client.run(os.environ["SBtoken"])
|
||||
except:
|
||||
print("[ERR] Client failed to run")
|
Loading…
Reference in a new issue