diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..2719268 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,13 @@ +kind: pipeline +name: default + +steps: +- name: test + image: python:3.10 + commands: + - pip install -r requirements.txt + - python -m unittest tests +trigger: + event: + exclude: + - pull_request diff --git a/.gitignore b/.gitignore index b15dfb2..b0771d7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ stroopwafel.ini Stroopwafel.sln Stroopwafel.pyproj *.txt +!requirements.txt *.sh -*.npy \ No newline at end of file +*.npy diff --git a/General.py b/General.py index 6d8bfda..9e7e9a8 100644 --- a/General.py +++ b/General.py @@ -8,7 +8,6 @@ import json, requests from discord.ext import commands from sympy import latex, symbols, preview, Symbol #for LaTeX images import youtube_dl -import ffmpeg class General(commands.Cog): """Overal toegestaan.""" @@ -16,6 +15,7 @@ class General(commands.Cog): def __init__(self, bot): self.bot = bot self.voice_states = {} + self.muzak_url = 'https://hdcon-muzak.herokuapp.com' self.r = praw.Reddit( user_agent='StroopwafelBot', client_secret=self.bot.tokens["redditSecret"], @@ -85,7 +85,7 @@ class General(commands.Cog): rkopieerpasta = self.r.subreddit('kopieerpasta') post = rkopieerpasta.random() - # Subreddits kunnen de random functie uitzetten, dus dit is de fallback: + # Subreddits kunnen de random functie uitzetten, dus dit is de fallback: if post == None: post = rkopieerpasta.top('month', limit=250) listing = list(post) @@ -121,15 +121,17 @@ Op kunt u bijvoorbeeld via een web-interface gifjes maken Namens de directie van Stroopwafel B.V. onze excuses voor dit ongemak.""") + def get_playlist_json(self): + return requests.get(self.muzak_url + '/stroopwafel') + @commands.command(pass_context=True) @asyncio.coroutine def playlist(self, ctx): """HDcon2021 playlist""" - muzak_url = 'https://hdcon-muzak.herokuapp.com' - data = json.loads(requests.get(muzak_url + '/stroopwafel').content) # als dit faalt yolo no catch - msg = 'Stemmen en nomineren kan hier: {}\n'.format(muzak_url) + data = json.loads(self.get_playlist_json().content) + msg = 'Stemmen en nomineren kan hier: {}\n'.format(self.muzak_url) msg += '*Er zijn al {} nummers genomineerd*\n'.format(data['stemCount']) - yield from ctx.channel.send(msg) + yield from ctx.channel.send(self.get_playlist_msg()) @commands.command(pass_context=True, hidden=True) @asyncio.coroutine diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5959dba --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +caldav +discord.py +praw +sympy +numpy +youtube_dl +python-ffmpeg diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..ea64811 --- /dev/null +++ b/tests.py @@ -0,0 +1,48 @@ +import unittest +import configparser +import praw +import random +import requests +import json + +import discord +from discord.ext import commands + +import General + +class TestGeneral(unittest.TestCase): + def setUp(self): + config = configparser.ConfigParser() + config.read('stroopwafel.ini') + self.tokens = config["tokens"] + self.r = praw.Reddit( + user_agent='StroopwafelBot', + client_secret=self.tokens["redditSecret"], + client_id=self.tokens["redditId"] + ) + self.r.read_only = True + intents = discord.Intents.default() + intents.message_content = True + intents.members = True + bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Stroopwafel. Shitpost bot extraordinaire.', pm_help=True, intents=intents) + bot.tokens = self.tokens + self.cog = General.General(bot) + + def test_aww(self): + # Duplicate code is tijdelijk!!!11one + raww = self.r.subreddit('aww+catloaf+tuckedinkitties+babyelephantgifs+babybigcatgifs+blep+holdmynip+gingerkitty+cathighfive+catsstandingup+catsareassholes+eyebleach') + post = raww.top('month', limit=250) + listing = list(post) + random.shuffle(listing) + post = listing[0] + print(post) + self.assertIsInstance(post,praw.models.Submission) + + def test_playlist(self): + data = self.cog.get_playlist_json() + with self.subTest(msg="Reddit doesn't return 200"): + self.assertEqual(data.status_code, 200) + with self.subTest(msg="Not a good response"): + self.assertIsInstance(data, requests.Response) + with self.subTest(msg="Does not convert to json"): + self.assertIsInstance(json.loads(data.content), dict) \ No newline at end of file