diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c1713d7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Peter van Arkel + +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. \ No newline at end of file diff --git a/env.py.dist b/env.py.dist deleted file mode 100644 index 2e8c8f8..0000000 --- a/env.py.dist +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env python3 - -TOKEN = 'discord-bot-token-here' \ No newline at end of file diff --git a/help/help.md b/help/help.md new file mode 100644 index 0000000..877e7d4 --- /dev/null +++ b/help/help.md @@ -0,0 +1 @@ +`General` \ No newline at end of file diff --git a/help/help_gifbot.md b/help/help_gifbot.md new file mode 100644 index 0000000..cd962f2 --- /dev/null +++ b/help/help_gifbot.md @@ -0,0 +1 @@ +`Test` \ No newline at end of file diff --git a/help/help_roll.md b/help/help_roll.md new file mode 100644 index 0000000..1821d99 --- /dev/null +++ b/help/help_roll.md @@ -0,0 +1,33 @@ +`!roll` +All forms of diceroll notations should work properly, including adding or detracting dice with each other, adding or detracting numbers from dicerolls, or even adding or detracting sums within brackets. Below are some examples. + +``` +Simple rolls + +!roll 1d20+6 +!roll 1d20-(2+6) +!roll 1d20-4+(1d4+3) + +Advanced rolls + +!roll 1d20x(N) +- exploding dice, will add extra dice on each roll above threshold N. If N is not defined, will default to maximum possible roll. + +!roll 6d6^(N) +- highest N dicerolls will be kept, so 6d6^2 will keep the highest two dice. + +!roll 6d6m(N) +- middle N dicerolls will be kept, so 6d6m2 will keep the middle two dice. + +!roll 6d6v(N) +- lowest N dicerolls will be kept, so 6d6l2 wil keep the lowest two dice. + +!roll 2d6r(N) +- will reroll any dice that are below threshold N. The reroll is possible to be below the threshold N. + +!roll 2d6rr(N) +- will reroll any dice that are below threshold N. The reroll will be at the very minimum threshold N. + +!roll 10d10s +- will sort the rolls in order, this will not change the result. +``` \ No newline at end of file diff --git a/jeeves b/jeeves deleted file mode 100644 index acfd63b..0000000 --- a/jeeves +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python3 - -import discord -from discord.ext import commands -import logging -import random -import urllib -from env import TOKEN - -# setup discord.py -client = discord.Client() -e = discord.Embed() -# setup logging -logger = logging.getLogger('jeeves') -logger.setLevel(logging.DEBUG) -handler = logging.FileHandler(filename='jeeves.log', encoding='utf-8', mode='w') -handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) -logger.addHandler(handler) - -def resolve(url): - return urllib.request.urlopen(url).url - -@client.event -async def on_message(message): - # we do not want the bot to reply to itself - if message.author == client.user: - return - if message.content.startswith('https://tenor.com/'): - crew = discord.Role.members("crew") - print(crew) - print(message.author) - #embed_url = message.content - #follow_url = embed_url + '.gif' - #full_url = resolve(follow_url) - #gif_url = full_url.split('?')[0] - #print(gif_url) - #embed = e.set_image(url=gif_url) - #await message.channel.send(embed=embed) - if message.content.startswith('https://giphy.com/'): - embed_url = message.content - image_code = embed_url.split('-')[-1] - gif_url = 'https://media.giphy.com/media/' + image_code + '/giphy.gif' - embed = e.set_image(url=gif_url) - await message.channel.send(embed=embed) - -@client.event -async def on_ready(): - print('### Active with id %s as %s ###' % (client.user.id,client.user.name) ) - # activity = discord.Activity(name='the threads of fate (pm !help for help)', type=discord.ActivityType.watching) - # await client.change_presence(activity=activity) - -if __name__ == '__main__': - client.run(TOKEN) \ No newline at end of file diff --git a/jeeves.py b/jeeves.py new file mode 100644 index 0000000..67e2cd8 --- /dev/null +++ b/jeeves.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +from types import resolve_bases +import discord +from discord.ext import commands +import logging +from jeevesbot import bothelp, functions, env + +# setup logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger('jeeves') +logger.setLevel(logging.INFO) +handler = logging.FileHandler(filename='jeeves.log', encoding='utf-8', mode='a') +handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) +logger.addHandler(handler) + +# setup discord.py +client = discord.Client() +e = discord.Embed() + +@client.event +async def on_message(message): + # we do not want the bot to reply to itself + if message.author == client.user: + return + if message.content.startswith('!help'): + parameters = message.content.split(' ', 1) + if len(parameters) == 2: + msg = format(bothelp.help(parameters[1])) + else: + msg = format(bothelp.help()) + await message.author.send(msg) + # giphy and tenor both have different structures to their links + if message.content.startswith('https://tenor.com/'): + roles = functions.checkrole(message.author.roles) + channel = functions.checkchannel(message.channel.id) + embed_url = message.content + follow_url = embed_url + '.gif' + full_url = functions.resolve(follow_url) + gif_url = full_url.split('?')[0] + embed = e.set_image(url=gif_url) + if channel is True: + if roles is not True: + await message.channel.send(embed=embed) + logger.info(message.author) + logger.info(gif_url) + if message.content.startswith('https://giphy.com/'): + roles = functions.checkrole(message.author.roles) + channel = functions.checkchannel(message.channel.id) + embed_url = message.content + image_code = embed_url.split('-')[-1] + gif_url = 'https://media.giphy.com/media/' + image_code + '/giphy.gif' + embed = e.set_image(url=gif_url) + if channel is True: + if roles is not True: + await message.channel.send(embed=embed) + logger.info(message.author) + logger.info(gif_url) + if message.content.startswith('!roll'): + parameters = message.content.split(' ', 1) + if len(parameters) == 2: + param = parameters[1] + roll,result = functions.roll(param) + msg = 'Rolling %s for {0.author.mention}: `%s`'.format(message) % (param,roll) + await message.channel.send(msg) + +@client.event +async def on_ready(): + print('### Active with id %s as %s ###' % (client.user.id,client.user.name) ) + activity = discord.Activity(name='Listening to !help', type=discord.ActivityType.listening) + +if __name__ == '__main__': + client.run(env.TOKEN) + +## TODO +# /tenor andere syntax +# tenor android keyboard andere syntax (https://c.tenor.com/) +# giphy verdubbelt url \ No newline at end of file diff --git a/jeevesbot/__init__.py b/jeevesbot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jeevesbot/__pycache__/__init__.cpython-38.pyc b/jeevesbot/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..811ae83 Binary files /dev/null and b/jeevesbot/__pycache__/__init__.cpython-38.pyc differ diff --git a/jeevesbot/__pycache__/bothelp.cpython-38.pyc b/jeevesbot/__pycache__/bothelp.cpython-38.pyc new file mode 100644 index 0000000..ed5366d Binary files /dev/null and b/jeevesbot/__pycache__/bothelp.cpython-38.pyc differ diff --git a/jeevesbot/__pycache__/env.cpython-38.pyc b/jeevesbot/__pycache__/env.cpython-38.pyc new file mode 100644 index 0000000..bcd7c56 Binary files /dev/null and b/jeevesbot/__pycache__/env.cpython-38.pyc differ diff --git a/jeevesbot/__pycache__/functions.cpython-38.pyc b/jeevesbot/__pycache__/functions.cpython-38.pyc new file mode 100644 index 0000000..e460fa5 Binary files /dev/null and b/jeevesbot/__pycache__/functions.cpython-38.pyc differ diff --git a/jeevesbot/bothelp.py b/jeevesbot/bothelp.py new file mode 100644 index 0000000..5a347e0 --- /dev/null +++ b/jeevesbot/bothelp.py @@ -0,0 +1,20 @@ +keywords = ['gifbot'] + +def help(keyword=''): + """Filter for general help or specific keyword help.""" + if not keyword: + file = open('help/help.md') + contents = file.read() + return (contents) + if keyword[0]: + keyword = str.lower(keyword) + if keyword in keywords: + document = 'help/help_' + keyword + '.md' + print(document) + file = open(document, 'r') + contents = file.read() + return (contents) + else: + file = open('help/help.md') + contents = file.read() + return (contents) \ No newline at end of file diff --git a/jeevesbot/env.py.dist b/jeevesbot/env.py.dist new file mode 100644 index 0000000..fb1ad44 --- /dev/null +++ b/jeevesbot/env.py.dist @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +TOKEN = 'discord-bot-token-here' +ADMIN_ROLE = 'role-to-exclude-from-gifbot' +GIFCHANNELS = 'add-channel-ids-for-bot-to-work-in' \ No newline at end of file diff --git a/jeevesbot/functions.py b/jeevesbot/functions.py new file mode 100644 index 0000000..b4e639a --- /dev/null +++ b/jeevesbot/functions.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python 3 + +from jeevesbot import env +import urllib +import dice + +# This function is necessary for tenor, because they do not allow linking directly to the gif and need resolving. +def resolve(url): + return urllib.request.urlopen(url).url + +# use the dice module for rolling +def roll(notation): + roll = dice.roll(notation) + result = int(roll) + return roll,result + +def checkrole(roles): + for role in roles: + if str(role) == env.ADMIN_ROLE: + return True + +def checkchannel(channelid): + if channelid in env.GIFCHANNELS: + return True + else: + return False diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0a5b11f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +aiohttp 3.7.4.post0 +async-timeout 3.0.1 +dice 3.1.2 +discord.py 1.7.1 +docopt 0.6.2 +multidict 5.1.0 +pyparsing 2.4.7 +typing-extensions 3.7.4.3 +yarl 1.6.3 \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e69de29