mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
Merge pull request #25 from 13xforever/new_fixes
New fixes & log results as embed
This commit is contained in:
@@ -54,23 +54,26 @@ class ApiResult(object):
|
||||
else:
|
||||
return "Product code {} was not found in compatibility database, possibly untested!".format(self.game_id)
|
||||
|
||||
def to_embed(self) -> Embed:
|
||||
def to_embed(self, infoInFooter = True) -> Embed:
|
||||
"""
|
||||
Makes an Embed representation of the object.
|
||||
:return: Embed representation of the object
|
||||
"""
|
||||
if self.status in self.status_map:
|
||||
return Embed(
|
||||
desc = "Status: {}, PR: {}, Updated: {}".format(
|
||||
self.status,
|
||||
self.pr if self.pr != "???" else """¯\_(ツ)_/¯""",
|
||||
datetime.strftime(self.date, datetime_output_format))
|
||||
result = Embed(
|
||||
title="[{}] {}".format(self.game_id, trim_string(self.title, 200)),
|
||||
url="https://forums.rpcs3.net/thread-{}.html".format(self.thread),
|
||||
color=self.status_map[self.status],
|
||||
).set_footer(
|
||||
text="Status: {}, PR: {}, Updated: {}".format(
|
||||
self.status,
|
||||
self.pr if self.pr != "???" else """¯\_(ツ)_/¯""",
|
||||
datetime.strftime(self.date, datetime_output_format)
|
||||
)
|
||||
)
|
||||
description = desc if not infoInFooter else None,
|
||||
color=self.status_map[self.status])
|
||||
if infoInFooter:
|
||||
return result.set_footer(text=desc)
|
||||
else:
|
||||
return result
|
||||
|
||||
else:
|
||||
return Embed(
|
||||
description="Product code {} was not found in compatibility database, possibly untested!".format(self.game_id),
|
||||
|
||||
9
bot.py
9
bot.py
@@ -19,7 +19,7 @@ from math_utils import limit_int
|
||||
from stream_handlers import stream_text_log, stream_gzip_decompress
|
||||
|
||||
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
|
||||
id_pattern = '(?P<letters>(?:[BPSUVX][CL]|P[ETU]|NP)[AEHJKPUIX][ABSM])[ \\-]?(?P<numbers>\\d{5})' # see http://www.psdevwiki.com/ps3/Productcode
|
||||
nsp = NumericStringParser()
|
||||
|
||||
bot_channel: TextChannel = None
|
||||
@@ -122,7 +122,8 @@ async def on_message(message: Message):
|
||||
print("Possible Buffer Overflow Attack Detected!")
|
||||
break
|
||||
elif error_code == LogAnalyzer.ERROR_STOP:
|
||||
await message.channel.send(log.get_report())
|
||||
await message.channel.send(log.get_text_report())
|
||||
#await message.channel.send(embed=log.get_embed_report())
|
||||
sent_log = True
|
||||
break
|
||||
elif error_code == LogAnalyzer.ERROR_FAIL:
|
||||
@@ -134,7 +135,7 @@ async def on_message(message: Message):
|
||||
|
||||
async def piracy_check(message: Message):
|
||||
for trigger in piracy_strings:
|
||||
if trigger in message.content:
|
||||
if trigger.lower() in message.content.lower(): #we should .lower() on trigger add ideally
|
||||
try:
|
||||
# permissions = message.channel.permissions_for(bot.user)
|
||||
# if permissions.manage_messages:
|
||||
@@ -574,6 +575,8 @@ async def piracy(ctx: Context):
|
||||
if await is_private_channel(ctx):
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send('Invalid piracy command passed...')
|
||||
else:
|
||||
ctx.invoked_subcommand = None
|
||||
|
||||
|
||||
# noinspection PyShadowingBuiltins
|
||||
|
||||
123
log_analyzer.py
123
log_analyzer.py
@@ -2,6 +2,7 @@ import re
|
||||
|
||||
from bot_config import piracy_strings
|
||||
from bot_utils import get_code
|
||||
from discord import Embed
|
||||
|
||||
SERIAL_PATTERN = re.compile('Serial: (?P<id>[A-z]{4}\\d{5})')
|
||||
LIBRARIES_PATTERN = re.compile('Load libraries:(?P<libraries>.*)', re.DOTALL | re.MULTILINE)
|
||||
@@ -26,8 +27,7 @@ class LogAnalyzer(object):
|
||||
|
||||
def get_id(self):
|
||||
try:
|
||||
info = get_code(re.search(SERIAL_PATTERN, self.buffer).group('id'))
|
||||
self.report = info.to_string() + '\n' + self.report
|
||||
self.product_info = get_code(re.search(SERIAL_PATTERN, self.buffer).group('id'))
|
||||
return self.ERROR_SUCCESS
|
||||
except AttributeError:
|
||||
print("Could not detect serial! Aborting!")
|
||||
@@ -38,8 +38,6 @@ class LogAnalyzer(object):
|
||||
self.libraries = [lib.strip().replace('.sprx', '')
|
||||
for lib
|
||||
in re.search(LIBRARIES_PATTERN, self.buffer).group('libraries').strip()[1:].split('-')]
|
||||
if len(self.libraries) > 0 and self.libraries[0] != "]": # [] when empty
|
||||
self.report += 'Selected Libraries: ' + ', '.join(self.libraries) + '\n\n'
|
||||
except KeyError as ke:
|
||||
print(ke)
|
||||
pass
|
||||
@@ -54,13 +52,11 @@ class LogAnalyzer(object):
|
||||
phase = (
|
||||
{
|
||||
'end_trigger': '·',
|
||||
'regex': re.compile('(?P<all>.*)', flags=re.DOTALL | re.MULTILINE),
|
||||
'string_format': '\n{all}\n'
|
||||
'regex': re.compile('(?P<build_and_specs>.*)', flags=re.DOTALL | re.MULTILINE),
|
||||
},
|
||||
{
|
||||
'end_trigger': 'Core:',
|
||||
'regex': None,
|
||||
'string_format': None,
|
||||
'function': [get_id, piracy_check]
|
||||
},
|
||||
{
|
||||
@@ -77,17 +73,11 @@ class LogAnalyzer(object):
|
||||
'Loader: (?P<lib_loader>.*?)\n.*?'
|
||||
'functions: (?P<hook_static_functions>.*?)\n.*',
|
||||
flags=re.DOTALL | re.MULTILINE),
|
||||
'string_format':
|
||||
'PPU Decoder: {ppu_decoder:>21s} | Thread Scheduler: {thread_scheduler}\n'
|
||||
'SPU Decoder: {spu_decoder:>21s} | SPU Threads: {spu_threads}\n'
|
||||
'SPU Lower Thread Priority: {spu_lower_thread_priority:>7s} | Hook Static Functions: {hook_static_functions}\n'
|
||||
'SPU Loop Detection: {spu_loop_detection:>14s} | Lib Loader: {lib_loader}\n\n',
|
||||
'function': get_libraries
|
||||
},
|
||||
{
|
||||
'end_trigger': 'Video:',
|
||||
'regex': None,
|
||||
'string_format': None,
|
||||
'function': None
|
||||
},
|
||||
{
|
||||
@@ -99,23 +89,17 @@ class LogAnalyzer(object):
|
||||
'VSync: (?P<vsync>.*?)\n.*?'
|
||||
'Use GPU texture scaling: (?P<gpu_texture_scaling>.*?)\n.*?'
|
||||
'Strict Rendering Mode: (?P<strict_rendering_mode>.*?)\n.*?'
|
||||
'Disable Vertex Cache: (?P<vertex_cache>.*?)\n.*?'
|
||||
'Resolution Scale: (?P<resolution_scale>.*?)\n.*?'
|
||||
'Anisotropic Filter Override: (?P<af_override>.*?)\n.*?'
|
||||
'Minimum Scalable Dimension: (?P<texture_scale_threshold>.*?)\n.*?'
|
||||
'D3D12:\s*\n\s*Adapter: (?P<d3d_gpu>.*?)\n.*?'
|
||||
'Vulkan:\s*\n\s*Adapter: (?P<vulkan_gpu>.*?)\n.*?',
|
||||
flags=re.DOTALL | re.MULTILINE),
|
||||
'string_format':
|
||||
'Renderer: {renderer:>24s} | Frame Limit: {frame_limit}\n'
|
||||
'Resolution: {resolution:>22s} | Write Color Buffers: {write_color_buffers}\n'
|
||||
'Resolution Scale: {resolution_scale:>16s} | Use GPU texture scaling: {gpu_texture_scaling}\n'
|
||||
'Resolution Scale Threshold: {texture_scale_threshold:>6s} | Anisotropic Filter Override: {af_override}\n'
|
||||
'Vulkan GPU: {vulkan_gpu:>22s} | D3D12 GPU: {d3d_gpu}\n'
|
||||
flags=re.DOTALL | re.MULTILINE)
|
||||
},
|
||||
{
|
||||
'end_trigger': 'Log:',
|
||||
'regex': None,
|
||||
'string_format': None,
|
||||
'function': done
|
||||
}
|
||||
)
|
||||
@@ -123,9 +107,9 @@ class LogAnalyzer(object):
|
||||
def __init__(self):
|
||||
self.buffer = ''
|
||||
self.phase_index = 0
|
||||
self.report = ''
|
||||
self.trigger = ''
|
||||
self.libraries = []
|
||||
self.parsed_data = {}
|
||||
|
||||
def feed(self, data):
|
||||
if len(self.buffer) > 16 * 1024 * 1024:
|
||||
@@ -137,6 +121,7 @@ class LogAnalyzer(object):
|
||||
self.buffer = ''
|
||||
self.phase_index += 1
|
||||
else:
|
||||
self.sanitize()
|
||||
return error_code
|
||||
else:
|
||||
self.buffer += '\n' + data
|
||||
@@ -144,7 +129,7 @@ class LogAnalyzer(object):
|
||||
|
||||
def process_data(self):
|
||||
current_phase = self.phase[self.phase_index]
|
||||
if current_phase['regex'] is not None and current_phase['string_format'] is not None:
|
||||
if current_phase['regex'] is not None:
|
||||
try:
|
||||
regex_result = re.search(current_phase['regex'], self.buffer.strip() + '\n')
|
||||
if regex_result is not None:
|
||||
@@ -156,15 +141,22 @@ class LogAnalyzer(object):
|
||||
if 'spu_secondary_cores' in group_args:
|
||||
group_args['thread_scheduler'] = group_args['spu_secondary_cores']
|
||||
if 'vulkan_gpu' in group_args and group_args['vulkan_gpu'] == '""':
|
||||
group_args['vulkan_gpu'] = 'Not set'
|
||||
group_args['vulkan_gpu'] = 'Unknown'
|
||||
if 'd3d_gpu' in group_args and group_args['d3d_gpu'] == '""':
|
||||
group_args['d3d_gpu'] = 'Not set'
|
||||
group_args['d3d_gpu'] = 'Unknown'
|
||||
if 'vulkan_gpu' in group_args:
|
||||
if group_args['vulkan_gpu'] != 'Unknown':
|
||||
group_args['gpu_info'] = group_args['vulkan_gpu']
|
||||
elif 'd3d_gpu' in group_args:
|
||||
group_args['gpu_info'] = group_args['d3d_gpu']
|
||||
else:
|
||||
group_args['gpu_info'] = 'Unknown'
|
||||
if 'af_override' in group_args:
|
||||
if group_args['af_override'] == '0':
|
||||
group_args['af_override'] = 'auto'
|
||||
elif group_args['af_override'] == '1':
|
||||
group_args['af_override'] = 'disabled'
|
||||
self.report += current_phase['string_format'].format(**group_args)
|
||||
self.parsed_data.update(group_args)
|
||||
except AttributeError as ae:
|
||||
print(ae)
|
||||
print("Regex failed!")
|
||||
@@ -183,8 +175,83 @@ class LogAnalyzer(object):
|
||||
pass
|
||||
return self.ERROR_SUCCESS
|
||||
|
||||
def sanitize(self):
|
||||
result = {}
|
||||
for k, v in self.parsed_data.items():
|
||||
result[k] = v.replace("`", "`\u200d").replace("<", "<\u200d") if v is not None else v
|
||||
self.parsed_data = result
|
||||
libs = []
|
||||
for l in self.libraries:
|
||||
libs.append(l.replace("`", "`\u200d").replace("<", "<\u200d") if l is not None else l)
|
||||
self.libraries = libs
|
||||
|
||||
def get_trigger(self):
|
||||
return self.trigger
|
||||
|
||||
def get_report(self):
|
||||
return '```\n{}```'.format(self.report)
|
||||
def get_text_report(self):
|
||||
additional_info = {
|
||||
'product_info': self.product_info.to_string(),
|
||||
'libs': ', '.join(self.libraries) if len(self.libraries) > 0 and self.libraries[0] != "]" else "None"
|
||||
}
|
||||
additional_info.update(self.parsed_data)
|
||||
return (
|
||||
'```'
|
||||
'{product_info}\n'
|
||||
'\n'
|
||||
'{build_and_specs}'
|
||||
'GPU: {gpu_info}\n'
|
||||
'\n'
|
||||
'PPU Decoder: {ppu_decoder:>21s} | Thread Scheduler: {thread_scheduler}\n'
|
||||
'SPU Decoder: {spu_decoder:>21s} | SPU Threads: {spu_threads}\n'
|
||||
'SPU Lower Thread Priority: {spu_lower_thread_priority:>7s} | Hook Static Functions: {hook_static_functions}\n'
|
||||
'SPU Loop Detection: {spu_loop_detection:>14s} | Lib Loader: {lib_loader}\n'
|
||||
'\n'
|
||||
'Selected Libraries: {libs}\n'
|
||||
'\n'
|
||||
'Renderer: {renderer:>24s} | Frame Limit: {frame_limit}\n'
|
||||
'Resolution: {resolution:>22s} | Write Color Buffers: {write_color_buffers}\n'
|
||||
'Resolution Scale: {resolution_scale:>16s} | Use GPU texture scaling: {gpu_texture_scaling}\n'
|
||||
'Resolution Scale Threshold: {texture_scale_threshold:>6s} | Anisotropic Filter Override: {af_override}\n'
|
||||
'VSync: {vsync:>27s} | Disable Vertex Cache: {vertex_cache}\n'
|
||||
'```'
|
||||
).format(**additional_info)
|
||||
|
||||
def get_embed_report(self):
|
||||
return self.product_info.to_embed(False).add_field(
|
||||
name='Build Info',
|
||||
value=(
|
||||
'{build_and_specs}'
|
||||
'GPU: {gpu_info}'
|
||||
).format(**self.parsed_data),
|
||||
inline=False
|
||||
).add_field(
|
||||
name='CPU Settings',
|
||||
value=(
|
||||
'PPU Decoder: {ppu_decoder}\n'
|
||||
'SPU Decoder: {spu_decoder}\n'
|
||||
'SPU Lower Thread Priority: {spu_lower_thread_priority}\n'
|
||||
'SPU Loop Detection: {spu_loop_detection}\n'
|
||||
'Thread Scheduler: {thread_scheduler}\n'
|
||||
'SPU Threads: {spu_threads}\n'
|
||||
'Hook Static Functions: {hook_static_functions}\n'
|
||||
'Lib Loader: {lib_loader}\n'
|
||||
).format(**self.parsed_data),
|
||||
inline=True
|
||||
).add_field(
|
||||
name='GPU Settings',
|
||||
value=(
|
||||
'Renderer: {renderer}\n'
|
||||
'Resolution: {resolution}\n'
|
||||
'Resolution Scale: {resolution_scale}\n'
|
||||
'Resolution Scale Threshold: {texture_scale_threshold}\n'
|
||||
'Write Color Buffers: {write_color_buffers}\n'
|
||||
'Use GPU texture scaling: {gpu_texture_scaling}\n'
|
||||
'Anisotropic Filter Override: {af_override}\n'
|
||||
'Disable Vertex Cache: {vertex_cache}\n'
|
||||
).format(**self.parsed_data),
|
||||
inline=True
|
||||
).add_field(
|
||||
name="Selected Libraries",
|
||||
value=', '.join(self.libraries) if len(self.libraries) > 0 and self.libraries[0] != "]" else "None",
|
||||
inline=False
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user