Update README.md

Rename rpcs3Bot to bot for simplicity sake.
This commit is contained in:
Nicba1010
2018-02-17 13:03:09 +01:00
parent 9db767562b
commit a10794e631
2 changed files with 56 additions and 55 deletions

View File

@@ -6,6 +6,7 @@ Dependencies:
* `$ python3 -m pip install -U discord.py`
* pyparsing for python3 (distro package or through pip)
* requests for python3 (distro package or through pip)
* peewee for python3 (distro package or through pip)
Optional stuff for private testing:
@@ -13,7 +14,7 @@ Optional stuff for private testing:
* add a user bot to this new app (look at the bottom of the app page)
* notice the Bot User Token
* [add your new bot to your private server](https://discordapp.com/oauth2/authorize?client_id=BOTCLIENTID&scope=bot)
* change channel IDs in `bot.py` for your test server channels
* change IDs in `bot_config.py` for your channels and users
How to run:
* `$ python3 bot.py bot_user_token`

108
bot.py
View File

@@ -20,7 +20,7 @@ from math_utils import limit_int
from phases import LogAnalyzer
from stream_handlers import stream_text_log, stream_gzip_decompress
rpcs3Bot = Bot(command_prefix="!")
bot = Bot(command_prefix="!")
id_pattern = '(?P<letters>(?:[BPSUVX][CL]|P[ETU]|NP)[AEHJKPUIX][A-Z])[ \\-]?(?P<numbers>\\d{5})' # see http://www.psdevwiki.com/ps3/Productcode
nsp = NumericStringParser()
@@ -43,27 +43,27 @@ file_handlers = (
)
@rpcs3Bot.event
@bot.event
async def on_ready():
print('Logged in as:')
print(rpcs3Bot.user.name)
print(rpcs3Bot.user.id)
print(bot.user.name)
print(bot.user.id)
print('------')
@rpcs3Bot.event
@bot.event
async def on_message(message: Message):
"""
OnMessage event listener
:param message: message
"""
# Self reply detect
if message.author.id == rpcs3Bot.connection.user.id:
if message.author.id == bot.connection.user.id:
return
# Command detect
try:
if message.content[0] == "!":
return await rpcs3Bot.process_commands(message)
return await bot.process_commands(message)
except IndexError as ie:
print("Empty message! Could still have attachments.")
@@ -80,9 +80,9 @@ async def on_message(message: Message):
for code in code_list:
info = get_code(code)
if info is not None:
await rpcs3Bot.send_message(message.channel, '```{}```'.format(info))
await bot.send_message(message.channel, '```{}```'.format(info))
else:
await rpcs3Bot.send_message(message.channel, '```Serial not found in compatibility database, possibly '
await bot.send_message(message.channel, '```Serial not found in compatibility database, possibly '
'untested!```')
return
@@ -109,7 +109,7 @@ async def on_message(message: Message):
print("Possible Buffer Overflow Attack Detected!")
break
elif error_code == LogAnalyzer.ERROR_STOP:
await rpcs3Bot.send_message(
await bot.send_message(
message.channel,
log.get_report()
)
@@ -119,7 +119,7 @@ async def on_message(message: Message):
break
if not sent_log:
print("Log analyzer didn't finish, probably a truncated/invalid log!")
await rpcs3Bot.send_message(
await bot.send_message(
message.channel,
log.get_report()
)
@@ -129,7 +129,7 @@ async def on_message(message: Message):
async def piracy_alert(message: Message, trigger: str):
print(message.author.id)
await rpcs3Bot.send_message(
await bot.send_message(
message.channel,
"Pirated release detected {author}!\n"
"Please note that the RPCS3 community and it's developers do not support piracy!\n"
@@ -179,28 +179,28 @@ def stream_line_by_line_safe(stream: Response, func: staticmethod):
del buffer
@rpcs3Bot.command()
@bot.command()
async def math(*args):
"""Math, here you go Juhn"""
return await rpcs3Bot.say(nsp.eval(''.join(map(str, args))))
return await bot.say(nsp.eval(''.join(map(str, args))))
# noinspection PyShadowingBuiltins
@rpcs3Bot.command()
@bot.command()
async def credits(*args):
"""Author Credit"""
return await rpcs3Bot.say("```\nMade by Roberto Anic Banic aka nicba1010!\n```")
return await bot.say("```\nMade by Roberto Anic Banic aka nicba1010!\n```")
# noinspection PyMissingTypeHints
@rpcs3Bot.command(pass_context=True)
@bot.command(pass_context=True)
async def c(ctx, *args):
"""Searches the compatibility database, USE: !c searchterm """
await compat_search(ctx, *args)
# noinspection PyMissingTypeHints
@rpcs3Bot.command(pass_context=True)
@bot.command(pass_context=True)
async def compat(ctx, *args):
"""Searches the compatibility database, USE: !compat searchterm"""
await compat_search(ctx, *args)
@@ -218,7 +218,7 @@ async def compat_search(ctx, *args):
# noinspection PyMissingTypeHints
@rpcs3Bot.command(pass_context=True)
@bot.command(pass_context=True)
async def top(ctx, *args):
"""
Gets the x (default 10) top oldest/newest updated games
@@ -234,7 +234,7 @@ async def top(ctx, *args):
request = ApiRequest(ctx.message.author)
if len(args) == 0 or args[0] not in ("new", "old"):
print("Invalid command")
return await rpcs3Bot.send_message(discord.Object(id=bot_spam_id), invalid_command_text)
return await bot.send_message(discord.Object(id=bot_spam_id), invalid_command_text)
if len(args) >= 1:
if args[0] == "old":
@@ -256,7 +256,7 @@ async def top(ctx, *args):
await dispatch_message(string)
@rpcs3Bot.command(pass_context=True)
@bot.command(pass_context=True)
async def filters(ctx, *args):
message = "**Sorting directions (not used in top command)**\n"
message += "Ascending\n```" + str(directions["a"]) + "```\n"
@@ -283,7 +283,7 @@ async def filters(ctx, *args):
message += "**Release Types**\n"
message += "Blu-Ray\n```" + str(release_types["b"]) + "```\n"
message += "PSN\n```" + str(release_types["n"]) + "```\n"
await rpcs3Bot.send_message(ctx.message.author, message)
await bot.send_message(ctx.message.author, message)
async def dispatch_message(message: str):
@@ -292,14 +292,14 @@ async def dispatch_message(message: str):
:param message: message to dispatch
"""
for part in message.split(newline_separator):
await rpcs3Bot.send_message(discord.Object(id=bot_channel_id), part)
await bot.send_message(discord.Object(id=bot_channel_id), part)
@rpcs3Bot.command(pass_context=True)
@bot.command(pass_context=True)
async def latest(ctx, *args):
"""Get the latest RPCS3 build link"""
latest_build = json.loads(requests.get("https://update.rpcs3.net/?c=somecommit").content)['latest_build']
return await rpcs3Bot.send_message(
return await bot.send_message(
ctx.message.author,
"PR: {pr}\nWindows:\n\tTime: {win_time}\n\t{windows_url}\nLinux:\n\tTime: {linux_time}\n\t{linux_url}".format(
pr=latest_build['pr'],
@@ -315,13 +315,13 @@ async def greet():
"""
Greets on boot!
"""
await rpcs3Bot.wait_until_ready()
return await rpcs3Bot.send_message(discord.Object(id=bot_spam_id), boot_up_message)
await bot.wait_until_ready()
return await bot.send_message(discord.Object(id=bot_spam_id), boot_up_message)
# User requests
# noinspection PyMissingTypeHints,PyMissingOrEmptyDocstring
@rpcs3Bot.command(pass_context=True)
@bot.command(pass_context=True)
async def roll(ctx, *args):
"""Generates a random number between 0 and n (default 10)"""
n = 10
@@ -330,14 +330,14 @@ async def roll(ctx, *args):
n = int(args[0])
except ValueError:
pass
await rpcs3Bot.send_message(discord.Object(id=bot_spam_id), "You rolled a {}!".format(randint(0, n)))
await bot.send_message(discord.Object(id=bot_spam_id), "You rolled a {}!".format(randint(0, n)))
# noinspection PyMissingTypeHints,PyMissingOrEmptyDocstring
@rpcs3Bot.command(pass_context=True, name="8ball")
@bot.command(pass_context=True, name="8ball")
async def eight_ball(ctx, *args):
"""Generates a random answer to your question"""
await rpcs3Bot.send_message(discord.Object(id=bot_spam_id), choice([
await bot.send_message(discord.Object(id=bot_spam_id), choice([
"Nah mate", "Ya fo sho", "Fo shizzle mah nizzle", "Yuuuup", "Nope", "Njet", "Da", "Maybe", "I don't know",
"I don't care", "Affirmative", "Sure", "Yeah, why not", "Most likely", "Sim", "Oui", "Heck yeah!", "Roger that",
"Aye!", "Yes without a doubt m8!", "Who cares", "Maybe yes, maybe not", "Maybe not, maybe yes", "Ugh",
@@ -357,7 +357,7 @@ async def is_sudo(ctx: Context):
print("User is sudoer, allowed!")
return True
else:
await rpcs3Bot.send_message(
await bot.send_message(
message.channel,
"{mention} is not a sudoer, this incident will be reported!".format(mention=author.mention)
)
@@ -374,7 +374,7 @@ async def is_mod(ctx: Context):
print("User is moderator, allowed!")
return True
else:
await rpcs3Bot.send_message(
await bot.send_message(
message.channel,
"{mention} is not a mod, this incident will be reported!".format(mention=author.mention)
)
@@ -388,7 +388,7 @@ async def is_private_channel(ctx: Context):
if channel.is_private:
return True
else:
await rpcs3Bot.send_message(
await bot.send_message(
channel,
'{mention} https://i.imgflip.com/24qx11.jpg'.format(
mention=author.mention
@@ -397,12 +397,12 @@ async def is_private_channel(ctx: Context):
return False
@rpcs3Bot.group(pass_context=True)
@bot.group(pass_context=True)
async def sudo(ctx: Context):
if not await is_sudo(ctx):
ctx.invoked_subcommand = None
if ctx.invoked_subcommand is None:
await rpcs3Bot.say('Invalid !sudo command passed...')
await bot.say('Invalid !sudo command passed...')
@sudo.command(pass_context=True)
@@ -414,7 +414,7 @@ async def say(ctx: Context, *args):
channel: Channel = server.get_channel(args[0][2:-1]) \
if args[0][:2] == '<#' and args[0][-1] == '>' \
else origin_channel
await rpcs3Bot.send_message(
await bot.send_message(
channel,
' '.join(args if channel.id == origin_channel.id else args[1:])
)
@@ -423,7 +423,7 @@ async def say(ctx: Context, *args):
@sudo.group(pass_context=True)
async def mod(ctx: Context):
if ctx.invoked_subcommand is None:
await rpcs3Bot.say('Invalid !sudo mod command passed...')
await bot.say('Invalid !sudo mod command passed...')
@mod.command(pass_context=True)
@@ -431,14 +431,14 @@ async def add(ctx: Context, user: Member):
moderator: Moderator = Moderator.get_or_none(Moderator.discord_id == user.id)
if moderator is None:
Moderator(discord_id=user.id).save()
await rpcs3Bot.say(
await bot.say(
"{mention} successfully added as moderator, you now have access to editing the piracy trigger list "
"and other useful things! I will send you the available commands to your message box!".format(
mention=user.mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"{mention} is already a moderator!".format(
mention=user.mention
)
@@ -451,26 +451,26 @@ async def delete(ctx: Context, user: Member):
if moderator is not None:
if moderator.discord_id != bot_admin_id:
if moderator.delete_instance():
await rpcs3Bot.say(
await bot.say(
"{mention} removed as moderator!".format(
mention=user.mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"Something went wrong!".format(
mention=user.mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"{author_mention} why would you even try this! Alerting {mention}!".format(
author_mention=ctx.message.author_mention.mention,
mention=ctx.message.server.get_member(bot_admin_id).mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"{mention} not found in moderators table!".format(
mention=user.mention
)
@@ -485,19 +485,19 @@ async def sudo(ctx: Context, user: Member):
if moderator.sudoer is False:
moderator.sudoer = True
moderator.save()
await rpcs3Bot.say(
await bot.say(
"{mention} successfully granted sudo permissions!".format(
mention=user.mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"{mention} already has sudo permissions!".format(
mention=user.mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"{mention} does not exist in moderator list, please add as moderator with mod_add!".format(
mention=user.mention
)
@@ -515,39 +515,39 @@ async def unsudo(ctx: Context, user: Member):
if moderator.sudoer is True:
moderator.sudoer = False
moderator.save()
await rpcs3Bot.say(
await bot.say(
"Successfully took away sudo permissions from {mention}".format(
mention=user.mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"{mention} already doesn't have sudo permissions!".format(
mention=user.mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"{author_mention} why would you even try this! Alerting {mention}!".format(
author_mention=author.mention,
mention=server.get_member(bot_admin_id).mention
)
)
else:
await rpcs3Bot.say(
await bot.say(
"{mention} does not exist in moderator list!".format(
mention=user.mention
)
)
@rpcs3Bot.group(pass_context=True)
@bot.group(pass_context=True)
async def piracy_filter(ctx: Context, *args):
if await is_mod(ctx) and await is_private_channel(ctx):
if ctx.invoked_subcommand is None:
await rpcs3Bot.say('Invalid piracy_filter command passed...')
await bot.say('Invalid piracy_filter command passed...')
print(sys.argv[1])
init()
rpcs3Bot.run(sys.argv[1])
bot.run(sys.argv[1])