Merge remote-tracking branch 'origin/development' into development
# Conflicts: # src/cogs/git.py
This commit is contained in:
+40
-4
@@ -11,6 +11,7 @@ import logging
|
||||
import random
|
||||
import traceback
|
||||
import os
|
||||
import sys
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
@@ -27,9 +28,15 @@ logging.basicConfig(level='INFO')
|
||||
# If uvloop is installed, change to that eventloop policy as it
|
||||
# is more efficient
|
||||
try:
|
||||
import uvloop
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
del uvloop
|
||||
# https://stackoverflow.com/a/45700730
|
||||
if sys.platform == 'win32':
|
||||
loop = asyncio.ProactorEventLoop()
|
||||
asyncio.set_event_loop(loop)
|
||||
logging.warning('Detected Windows. Changing event loop to ProactorEventLoop.')
|
||||
else:
|
||||
import uvloop
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
del uvloop
|
||||
except BaseException as ex:
|
||||
logging.warning(f'Could not load uvloop. {type(ex).__qualname__}: {ex};',
|
||||
'reverting to default impl.')
|
||||
@@ -80,12 +87,16 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
||||
# CommandErrors triggered by other propagating errors tend to get wrapped. This means
|
||||
# if we have a cause, we should probably consider unwrapping that so we get a useful
|
||||
# message.
|
||||
|
||||
# If command is not found, return
|
||||
if isinstance(error, discord.ext.commands.errors.CommandNotFound):
|
||||
return
|
||||
|
||||
error = error.__cause__ or error
|
||||
tb = traceback.format_exception(type(error), error, error.__traceback__, limit=2, chain=False)
|
||||
tb = ''.join(tb)
|
||||
joke = random.choice(jokes)
|
||||
fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n```py\n{tb}\n```'
|
||||
simple_fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n**`{error}`**'
|
||||
|
||||
# Stops the error handler erroring.
|
||||
try:
|
||||
@@ -94,6 +105,31 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
async def on_message(self, message):
|
||||
# Make sure people can't change the username
|
||||
if message.guild:
|
||||
if message.guild.me.display_name != self.display_name:
|
||||
try:
|
||||
await message.guild.me.edit(nick=self.display_name)
|
||||
except:
|
||||
pass
|
||||
|
||||
# If author is a bot, ignore the message
|
||||
if message.author.bot: return
|
||||
|
||||
# Make sure the command get processed as if it was typed with lowercase
|
||||
# Split message.content one first space
|
||||
command = message.content.split(None, 1)
|
||||
if command:
|
||||
command[0] = command[0].lower()
|
||||
message.content = ' '.join(command)
|
||||
message.content = ' '.join(command)
|
||||
|
||||
# process command
|
||||
await self.process_commands(message)
|
||||
|
||||
|
||||
|
||||
client = SebiMachine()
|
||||
# Make sure the key stays private.
|
||||
# I am 99% certain this is valid!
|
||||
|
||||
+95
-95
@@ -1,95 +1,95 @@
|
||||
"""
|
||||
===
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Dusty.P https://github.com/dustinpianalto
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from src.shared_libs.utils import paginate, run_command
|
||||
from src.shared_libs.loggable import Loggable
|
||||
import asyncio
|
||||
|
||||
|
||||
class Git(Loggable):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.group(case_insensitive=True, invoke_without_command=True)
|
||||
async def git(self, ctx):
|
||||
"""Run help git for more info"""
|
||||
await ctx.send('https://github.com/Annihilator708/Sebi-Machine/')
|
||||
|
||||
@commands.command(case_insensitive=True, brief='Gets the Trello link.')
|
||||
async def trello(self, ctx):
|
||||
await ctx.send('<https://trello.com/b/x02goBbW/sebis-bot-tutorial-roadmap>')
|
||||
|
||||
@git.command()
|
||||
async def pull(self, ctx):
|
||||
self.logger.warning('Invoking git-pull')
|
||||
await ctx.trigger_typing()
|
||||
if ctx.author.id not in self.bot.ownerlist:
|
||||
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||
em = discord.Embed(style='rich',
|
||||
title=f'Git Pull',
|
||||
color=self.bot.embed_color)
|
||||
em.set_thumbnail(url=f'{ctx.guild.me.avatar_url}')
|
||||
|
||||
# Pretty sure you can just do await run_command() if that is async,
|
||||
# or run in a TPE otherwise.
|
||||
result = await asyncio.wait_for(self.bot.loop.create_task(
|
||||
run_command('git fetch --all')), 120) + '\n'
|
||||
result += await asyncio.wait_for(self.bot.loop.create_task(
|
||||
run_command('git reset --hard origin/$(git rev-parse '
|
||||
'--symbolic-full-name --abbrev-ref HEAD)')),
|
||||
120) + '\n\n'
|
||||
result += await asyncio.wait_for(self.bot.loop.create_task(
|
||||
run_command('git show --stat | sed "s/.*@.*[.].*/ /g"')), 10)
|
||||
|
||||
results = paginate(result, maxlen=1014)
|
||||
for page in results[:5]:
|
||||
em.add_field(name='\uFFF0', value=f'{page}')
|
||||
await ctx.send(embed=em)
|
||||
|
||||
@git.command()
|
||||
async def status(self, ctx):
|
||||
await ctx.trigger_typing()
|
||||
if ctx.author.id not in self.bot.ownerlist:
|
||||
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||
em = discord.Embed(style='rich',
|
||||
title=f'Git Status',
|
||||
color=self.bot.embed_color)
|
||||
em.set_thumbnail(url=f'{ctx.guild.me.avatar_url}')
|
||||
result = await asyncio.wait_for(self.bot.loop.create_task(
|
||||
run_command('git status')), 10)
|
||||
results = paginate(result, maxlen=1014)
|
||||
for page in results[:5]:
|
||||
em.add_field(name='\uFFF0', value=f'{page}')
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Git(bot))
|
||||
"""
|
||||
===
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Dusty.P https://github.com/dustinpianalto
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from src.shared_libs.utils import paginate, run_command
|
||||
from src.shared_libs.loggable import Loggable
|
||||
import asyncio
|
||||
|
||||
|
||||
class Git(Loggable):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.group(case_insensitive=True, invoke_without_command=True)
|
||||
async def git(self, ctx):
|
||||
"""Run help git for more info"""
|
||||
await ctx.send('https://github.com/Annihilator708/Sebi-Machine/')
|
||||
|
||||
@commands.command(case_insensitive=True, brief='Gets the Trello link.')
|
||||
async def trello(self, ctx):
|
||||
await ctx.send('<https://trello.com/b/x02goBbW/sebis-bot-tutorial-roadmap>')
|
||||
|
||||
@git.command()
|
||||
async def pull(self, ctx):
|
||||
self.logger.warning('Invoking git-pull')
|
||||
await ctx.trigger_typing()
|
||||
if ctx.author.id not in self.bot.ownerlist:
|
||||
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||
em = discord.Embed(style='rich',
|
||||
title=f'Git Pull',
|
||||
color=self.bot.embed_color)
|
||||
em.set_thumbnail(url=f'{ctx.guild.me.avatar_url}')
|
||||
|
||||
# Pretty sure you can just do await run_command() if that is async,
|
||||
# or run in a TPE otherwise.
|
||||
result = await asyncio.wait_for(self.bot.loop.create_task(
|
||||
run_command('git fetch --all')), 120) + '\n'
|
||||
result += await asyncio.wait_for(self.bot.loop.create_task(
|
||||
run_command('git reset --hard origin/$(git rev-parse '
|
||||
'--symbolic-full-name --abbrev-ref HEAD)')),
|
||||
120) + '\n\n'
|
||||
result += await asyncio.wait_for(self.bot.loop.create_task(
|
||||
run_command('git show --stat | sed "s/.*@.*[.].*/ /g"')), 10)
|
||||
|
||||
results = paginate(result, maxlen=1014)
|
||||
for page in results[:5]:
|
||||
em.add_field(name='\uFFF0', value=f'{page}')
|
||||
await ctx.send(embed=em)
|
||||
|
||||
@git.command()
|
||||
async def status(self, ctx):
|
||||
await ctx.trigger_typing()
|
||||
if ctx.author.id not in self.bot.ownerlist:
|
||||
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||
em = discord.Embed(style='rich',
|
||||
title=f'Git Status',
|
||||
color=self.bot.embed_color)
|
||||
em.set_thumbnail(url=f'{ctx.guild.me.avatar_url}')
|
||||
result = await asyncio.wait_for(self.bot.loop.create_task(
|
||||
run_command('git status')), 10)
|
||||
results = paginate(result, maxlen=1014)
|
||||
for page in results[:5]:
|
||||
em.add_field(name='\uFFF0', value=f'{page}')
|
||||
await ctx.send(embed=em)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Git(bot))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 0.1,
|
||||
"display_name" : "[S!] Sebi-Machine",
|
||||
"display_name" : "[ds!] Dev-Sebi",
|
||||
"maintenance": "True",
|
||||
"ownerlist": [],
|
||||
"prefix": "S!"
|
||||
}
|
||||
"prefix": "ds!"
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ class LoadConfig:
|
||||
# Initialize config
|
||||
|
||||
self.ownerlist = self.config["ownerlist"]
|
||||
if self.ownerlist == []:
|
||||
self.ownerlist = [int(i) for i in os.getenv('ownerlist').split(',')]
|
||||
self.defaultprefix = self.config["prefix"]
|
||||
self.version = self.config["version"]
|
||||
self.display_name = self.config["display_name"]
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"""
|
||||
IO stuff.
|
||||
"""
|
||||
import copy
|
||||
import inspect
|
||||
import os
|
||||
|
||||
@@ -42,13 +43,20 @@ def in_here(first_path_bit: str, *path_bits: str, stack_depth: int=0) -> str:
|
||||
raise RuntimeError('Could not find a stack record. Interpreter has '
|
||||
'been shot.')
|
||||
else:
|
||||
module = inspect.getmodule(frame[0])
|
||||
module = inspect.getmodule(frame[0])
|
||||
assert hasattr(module, '__file__'), 'No `__file__\' attr, welp.'
|
||||
|
||||
|
||||
# https://docs.python.org/3/library/inspect.html#the-interpreter-stack
|
||||
# If Python caches strings rather than copying when we move them
|
||||
# around or modify them, then this may cause a referential cycle which
|
||||
# will consume more memory and stop the garbage collection system
|
||||
# from working correctly. Best thing to do here is deepcopy anything
|
||||
# we need and prevent this occuring. Del the references to allow them
|
||||
# to be freed.
|
||||
file = module.__file__
|
||||
|
||||
file = copy.deepcopy(file)
|
||||
del module, frame
|
||||
dir_name = os.path.dirname(file)
|
||||
abs_dir_name = os.path.abspath(dir_name)
|
||||
|
||||
pathish = os.path.join(abs_dir_name, first_path_bit, *path_bits)
|
||||
return pathish
|
||||
|
||||
Reference in New Issue
Block a user