Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds github command and searcher #7

Open
wants to merge 1 commit into
base: RBHbot
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions rh1/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,43 @@ async def wrapper(self, *args, **kwargs):

wrapper.mod_cmd = True
return wrapper

async def cmd_gh(self, message, channel, author, guild):
"""
Usage: {command_prefix}gh
Shows information from github
"""
#stolen from r.danny: https://github.com/Rapptz/RoboDanny/blob/rewrite/cogs/stats.py#L218-#L-231
def format_commit(self, commit):
short, _, _ = commit.message.partition('\n')
short_sha2 = commit.hex[0:6]
commit_tz = datetime.timezone(datetime.timedelta(minutes=commit.commit_time_offset))
commit_time = datetime.datetime.fromtimestamp(commit.commit_time).replace(tzinfo=commit_tz)

# [`hash`](url) message (offset)
offset = time.human_timedelta(commit_time.astimezone(datetime.timezone.utc).replace(tzinfo=None), accuracy=1)
return f'[`{short_sha2}`](https://github.com/srhinos/rsb/commit/{commit.hex}) {short} ({offset})'

def get_last_commits(self, count=3):
repo = pygit2.Repository('.git')
commits = list(itertools.islice(repo.walk(repo.head.target, pygit2.GIT_SORT_TOPOLOGICAL), count))
return '\n'.join(self.format_commit(c) for c in commits)

revision = self.get_last_commits()
embed = discord.Embed(description='Latest Changes:\n' + revision)
embed.title = 'Support Server'
embed.url = 'discord.gg/bots'
embed.colour = discord.Colour.blurple()
embed.image = self.avatar_url()

owner = self.bot.get_user(self.bot.owner_id)
embed.set_author(name=str(owner), icon_url=owner.avatar_url)

embed.add_field(name='Source Code', value='https://github.com/srhinos/rsb/tree/r6bot', inline=False)
embed.add_field(name='Issues', value='https://github.com/srhinos/rsb/issues', inline=True)
embed.add_field(name='Pull Request', value='https://github.com/srhinos/rsb/pulls', inline=True)

await self.safe_send_message(message.channel, content=embed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is simple enough that we could just add it as a tag


@mods_only
async def cmd_alias(self, guild, raw_leftover_args):
Expand Down Expand Up @@ -3340,6 +3377,27 @@ async def on_message(self, message, edit=False):
if message.author == self.user:
return

if ininstance(messsage.channel, discord.abc.GuildChannel):
if not int(message.content[len(self.command_prefix):]):
return

try:
import httplib
c = httplib.HTTPConnection('https://github.com/srhinos/rsb/issues/' + message.content[len(self.command_prefix):])
c.request("HEAD", '')
if c.getresponse().status == 200:
await self.safe_send_message(message.channel, c)
else:
try:
import httplib
c = httplib.HTTPConnection('https://github.com/srhinos/rsb/pull/' + message.content[len(self.command_prefix):])
if c.getresponse().status == 200:
await self.safe_send_message(message.channel, c)
except:
return
except:
return

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is something would fit into the bot. I'd much rather THIS be the command where you run !gh <num> and it attempts to fetch either or with qualifying info.

if isinstance(message.channel, discord.abc.PrivateChannel):
member_object = discord.utils.get(discord.utils.get(self.guilds, id=SERVERS['main']).members, id=message.author.id)
message.author = member_object
Expand Down