This repository has been archived by the owner on Nov 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
125 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import logging | ||
import time | ||
|
||
# Force UTC Timestamps | ||
# From the logging cookbook: https://docs.python.org/3/howto/logging-cookbook.html | ||
class UTCFormatter(logging.Formatter): | ||
converter = time.gmtime | ||
|
||
logformat = '%(asctime)s %(levelname)s:%(module)s:%(message)s' | ||
dateformat = '%Y-%m-%d %H:%M:%S' | ||
logging.basicConfig(filename='./log/wumbot.log', filemode='a', level=logging.INFO, | ||
format=logformat, datefmt=dateformat | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import re | ||
import typing | ||
|
||
import discord | ||
from discord.ext import commands | ||
|
||
class Reddit(): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@staticmethod | ||
def buildSubredditEmbed(subredditlist: typing.List[str], embedlimit: int=3): | ||
""" | ||
Build a message embed from a list of subreddit strings (sans '/r/') | ||
Limit to embedlimit number of subreddits per embed, for brevity. Default is 3 | ||
""" | ||
snooURL = "https://images-eu.ssl-images-amazon.com/images/I/418PuxYS63L.png" | ||
|
||
embed = discord.Embed(color=discord.Color(0x9c4af7)) | ||
embed.set_thumbnail(url=snooURL) | ||
embed.set_author(name='Subreddit Embedder 9000') | ||
embed.set_footer(text='Reddit', icon_url=snooURL) | ||
|
||
if len(subredditlist) == 1: | ||
embed.description = "Subreddit detected!" | ||
subreddit = subredditlist[0] | ||
embed.add_field(name=f"/r/{subreddit}", value=f"https://www.reddit.com/r/{subreddit}", inline=False) | ||
else: | ||
embed.description = "Subreddits detected!" | ||
for subreddit in subredditlist[0:embedlimit]: | ||
embed.add_field(name=f"/r/{subreddit}", value=f"https://www.reddit.com/r/{subreddit}", inline=False) | ||
|
||
if len(subredditlist) > embedlimit: | ||
embed.add_field(name="Note:", value=f"For brevity, only {embedlimit} subreddits have been embedded. You linked {len(subredditlist)}") | ||
|
||
return embed | ||
|
||
async def on_message(self, message: discord.Message): | ||
# Avoid self-replies | ||
if message.author.id == self.bot.user.id: | ||
return | ||
|
||
# Check to see if /r/_subreddit (e.g. /r/python) has been typed & add a Reddit embed | ||
# Ignores regular reddit links (e.g. http://www.reddit.com/r/Python) | ||
testSubreddit = re.findall(r'(?:^|\s)\/?[rR]\/(\w+)', message.content) | ||
if testSubreddit: | ||
logging.info(f"Subreddit(s) detected: '{testSubreddit}'") | ||
logging.info(f"Original message: '{message.content}'") | ||
SubredditEmbed = self.buildSubredditEmbed(testSubreddit) | ||
await message.channel.send(embed=SubredditEmbed) | ||
|
||
# Check to see if Reddit's stupid image/video hosting has added 'DashPlaylist.mpd' | ||
# to the end of the URL, which links to a direct download (of nothing) rather | ||
# than the web content | ||
testVreddit = re.search(r'(https?:\/\/v.redd.it\/.*)(DASHPlaylist.*$)', message.content) | ||
if testVreddit: | ||
newURL = testVreddit.group(1) | ||
logging.info(f"VReddit MPD detected: '{testVreddit.group(0)}'") | ||
logging.info(f"Link converted to: {newURL}") | ||
await message.channel.send(f"Here {message.author.mention}, let me fix that v.redd.it link for you: {newURL}") | ||
|
||
|
||
def setup(bot): | ||
bot.add_cog(Reddit(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import discord | ||
|
||
def isOwner(user: discord.User) -> bool: | ||
""" | ||
Check to see if the input User's ID matches the Owner ID | ||
""" | ||
ownerID = 129606635545952258 | ||
return user.id == ownerID | ||
|
||
def isDM(channel: discord.TextChannel) -> bool: | ||
""" | ||
Check to see if a channel is a DM | ||
A DM is either an instance of DMChannel or GroupChannel | ||
""" | ||
return isinstance(channel, (discord.DMChannel, discord.GroupChannel)) | ||
|
||
def isWumbologist(member: discord.Member) -> bool: | ||
""" | ||
Check to see if a discord.Member has the 'Wumbologists' role | ||
""" | ||
return 'Wumbologists' in [str(role) for role in member.roles] |
Empty file.
File renamed without changes.