From 48ee329b8828b5fe4ccf3b72ad6020db67a8b52e Mon Sep 17 00:00:00 2001 From: taaku251 <45324516+Taaku18@users.noreply.github.com> Date: Mon, 14 Jan 2019 20:50:29 -0800 Subject: [PATCH 1/9] Updated .gitignore Added pycharm and macos ignores, unignore app.json (apparently it was excluded by *.json) --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 869fd829e3..412262e06d 100644 --- a/.gitignore +++ b/.gitignore @@ -100,6 +100,12 @@ ENV/ # mypy .mypy_cache/ *.json +!app.json +#Pycharm +.idea/ + +#MacOs +.DS_Store config.json From 1cd295753ca46a07c03a0d95361c1a2cb3e508f4 Mon Sep 17 00:00:00 2001 From: taaku251 <45324516+Taaku18@users.noreply.github.com> Date: Mon, 14 Jan 2019 21:31:31 -0800 Subject: [PATCH 2/9] Added status command --- cogs/modmail.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cogs/modmail.py b/cogs/modmail.py index ab7e0037e7..e5d087417f 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -2,10 +2,11 @@ import datetime from typing import Optional, Union -import re import discord from discord.ext import commands +from discord.enums import ActivityType + import dateutil.parser from core.decorators import trigger_typing @@ -124,6 +125,19 @@ async def move(self, ctx, *, category: discord.CategoryChannel): await thread.channel.edit(category=category) await ctx.message.add_reaction('✅') + @commands.command() + async def status(self, ctx, activity_type: str, *, message: str): + activity_type = ActivityType[activity_type] + self.bot: commands.Bot + activity = discord.Activity(type=activity_type, name=message) + await self.bot.change_presence(activity=activity) + em = discord.Embed( + title='Status Changed', + description=f'{ActivityType(activity_type)}: {message}.', + color=discord.Color.green() + ) + await ctx.send(embed=em) + async def send_scheduled_close_message(self, ctx, after, silent=False): human_delta = human_timedelta(after.dt) From ef210738ad47fa20f1b839204db287ff9a84f10d Mon Sep 17 00:00:00 2001 From: taaku251 <45324516+Taaku18@users.noreply.github.com> Date: Mon, 14 Jan 2019 21:51:51 -0800 Subject: [PATCH 3/9] Move activity type to utility.py --- cogs/modmail.py | 14 -------------- cogs/utility.py | 38 +++++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/cogs/modmail.py b/cogs/modmail.py index e5d087417f..5ae3eb1534 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -5,7 +5,6 @@ import discord from discord.ext import commands -from discord.enums import ActivityType import dateutil.parser @@ -125,19 +124,6 @@ async def move(self, ctx, *, category: discord.CategoryChannel): await thread.channel.edit(category=category) await ctx.message.add_reaction('✅') - @commands.command() - async def status(self, ctx, activity_type: str, *, message: str): - activity_type = ActivityType[activity_type] - self.bot: commands.Bot - activity = discord.Activity(type=activity_type, name=message) - await self.bot.change_presence(activity=activity) - em = discord.Embed( - title='Status Changed', - description=f'{ActivityType(activity_type)}: {message}.', - color=discord.Color.green() - ) - await ctx.send(embed=em) - async def send_scheduled_close_message(self, ctx, after, silent=False): human_delta = human_timedelta(after.dt) diff --git a/cogs/utility.py b/cogs/utility.py index 85a6cd6296..79ae3f1f06 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -1,5 +1,7 @@ import discord from discord.ext import commands +from discord.enums import ActivityType + import datetime import traceback import inspect @@ -268,26 +270,36 @@ async def update(self, ctx): await ctx.send(embed=em) - @commands.command(name='status', aliases=['customstatus', 'presence']) + @commands.command(aliases=['presence']) @commands.has_permissions(administrator=True) - async def _status(self, ctx, *, message): - """Set a custom playing status for the bot. - - Set the message to `clear` if you want to remove the playing status. + async def status(self, ctx, activity_type: str, *, message: str = ''): """ + Set a custom playing status for the bot. - if message == 'clear': - self.bot.config['status'] = None + [prefix]status activity message... + + Set the message to `clear` if you want to remove the status. + """ + if activity_type == 'clear': + await self.bot.change_presence(activity=None) + self.bot.config['activity_type'] = None + self.bot.config['activity_message'] = None await self.bot.config.update() - return await self.bot.change_presence(activity=None) + return - await self.bot.change_presence(activity=discord.Game(message)) - self.bot.config['status'] = message + activity_type = ActivityType[activity_type] + self.bot: commands.Bot + activity = discord.Activity(type=activity_type, name=message) + await self.bot.change_presence(activity=activity) + self.bot.config['activity_type'] = activity_type + self.bot.config['activity_message'] = message await self.bot.config.update() - em = discord.Embed(title='Status Changed') - em.description = message - em.color = discord.Color.green() + em = discord.Embed( + title='Status Changed', + description=f'{ActivityType(activity_type)}: {message}.', + color=discord.Color.green() + ) await ctx.send(embed=em) @commands.command() From fab3f7b45dd9718a09db845647d74764185d5152 Mon Sep 17 00:00:00 2001 From: taaku251 <45324516+Taaku18@users.noreply.github.com> Date: Mon, 14 Jan 2019 22:10:00 -0800 Subject: [PATCH 4/9] rename status to activity Status can be later used for online/idle/busy as per discord rewrite convention --- cogs/utility.py | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/cogs/utility.py b/cogs/utility.py index 79ae3f1f06..e3f2248cbd 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -267,28 +267,47 @@ async def update(self, ctx): else: em.description = 'Already up to date with master repository.' - await ctx.send(embed=em) @commands.command(aliases=['presence']) @commands.has_permissions(administrator=True) - async def status(self, ctx, activity_type: str, *, message: str = ''): + async def activity(self, ctx, activity_type: str, *, message: str = ''): """ - Set a custom playing status for the bot. + Set a custom activity for the bot. - [prefix]status activity message... + Possible activity types: `playing`, `streaming`, `listening`, `watching`, `clear` - Set the message to `clear` if you want to remove the status. + When activity type is set to `clear`, the current activity is removed. """ if activity_type == 'clear': await self.bot.change_presence(activity=None) self.bot.config['activity_type'] = None self.bot.config['activity_message'] = None await self.bot.config.update() - return + em = discord.Embed( + title='Activity Removed', + color=discord.Color.green() + ) + return await ctx.send(embed=em) + + if not message: + em = discord.Embed( + title='Invalid Message', + description='You must set an activity message.', + color=discord.Color.red() + ) + return await ctx.send(embed=em) + + try: + activity_type = ActivityType[activity_type] + except KeyError: + em = discord.Embed( + title='Invalid Activity Type', + description=f'Cannot set activity to: {activity_type}.', + color=discord.Color.red() + ) + return await ctx.send(embed=em) - activity_type = ActivityType[activity_type] - self.bot: commands.Bot activity = discord.Activity(type=activity_type, name=message) await self.bot.change_presence(activity=activity) self.bot.config['activity_type'] = activity_type @@ -296,11 +315,11 @@ async def status(self, ctx, activity_type: str, *, message: str = ''): await self.bot.config.update() em = discord.Embed( - title='Status Changed', - description=f'{ActivityType(activity_type)}: {message}.', + title='Activity Changed', + description=f'Current activity is: {activity_type.name} {message}.', color=discord.Color.green() ) - await ctx.send(embed=em) + return await ctx.send(embed=em) @commands.command() @trigger_typing From 572421833381ba30317e7af446963abeb3b74203 Mon Sep 17 00:00:00 2001 From: taaku251 <45324516+Taaku18@users.noreply.github.com> Date: Mon, 14 Jan 2019 22:15:31 -0800 Subject: [PATCH 5/9] Replaced config status in bot.py to activity_type and activity_message --- bot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 1272e3c39c..5e1e132aa2 100644 --- a/bot.py +++ b/bot.py @@ -175,9 +175,12 @@ async def on_connect(self): print(line) print(Fore.CYAN + 'Connected to gateway.') await self.config.refresh() - status = self.config.get('status') - if status: - await self.change_presence(activity=discord.Game(status)) + + activity_type = self.config.get('activity_type') + message = self.config.get('activity_message') + if activity_type and message: + activity = discord.Activity(type=activity_type, name=message) + await self.change_presence(activity=activity) async def on_ready(self): """Bot startup, sets uptime.""" From 641efbcb2d9e570b5d730f6a78629eb3dac7c9f2 Mon Sep 17 00:00:00 2001 From: taaku251 <45324516+Taaku18@users.noreply.github.com> Date: Mon, 14 Jan 2019 23:06:01 -0800 Subject: [PATCH 6/9] Incremented version, add fix for when activity is set to streaming --- CHANGELOG.md | 9 +++++++++ bot.py | 7 +++++-- cogs/utility.py | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0e1134085..0b6badb56f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# v2.3.1 + +### Added +- Added the `activity` command for setting the activity +- [PR #131](https://github.com/kyb3r/modmail/pull/131#issue-244686818) + +### Removed +- Removed the deprecated `status` command. + # v2.3.0 ### Added diff --git a/bot.py b/bot.py index 5e1e132aa2..faf4998cc9 100644 --- a/bot.py +++ b/bot.py @@ -22,7 +22,7 @@ SOFTWARE. """ -__version__ = '2.3.0' +__version__ = '2.3.1' import asyncio import textwrap @@ -33,6 +33,7 @@ import discord import aiohttp +from discord.enums import ActivityType from discord.ext import commands from discord.ext.commands.view import StringView from motor.motor_asyncio import AsyncIOMotorClient @@ -179,7 +180,9 @@ async def on_connect(self): activity_type = self.config.get('activity_type') message = self.config.get('activity_message') if activity_type and message: - activity = discord.Activity(type=activity_type, name=message) + url = 'https://www.twitch.tv/discord-modmail/' if activity_type == ActivityType.streaming else None + activity = discord.Activity(type=activity_type, name=message, + url=url) await self.change_presence(activity=activity) async def on_ready(self): diff --git a/cogs/utility.py b/cogs/utility.py index e3f2248cbd..ffe93b8406 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -308,7 +308,8 @@ async def activity(self, ctx, activity_type: str, *, message: str = ''): ) return await ctx.send(embed=em) - activity = discord.Activity(type=activity_type, name=message) + url = 'https://www.twitch.tv/discord-modmail/' if activity_type == ActivityType.streaming else None + activity = discord.Activity(type=activity_type, name=message, url=url) await self.bot.change_presence(activity=activity) self.bot.config['activity_type'] = activity_type self.bot.config['activity_message'] = message From e8b845844c046bef6e94c34e2f92ea2e34887125 Mon Sep 17 00:00:00 2001 From: Kyber Date: Tue, 15 Jan 2019 18:11:55 +1100 Subject: [PATCH 7/9] Update CHANGELOG.md --- CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b6badb56f..8fe320a0d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,14 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -# v2.3.1 +# v2.4.0 + +Breaking changes for bot status. ### Added - Added the `activity` command for setting the activity -- [PR #131](https://github.com/kyb3r/modmail/pull/131#issue-244686818) +- [PR #131](https://github.com/kyb3r/modmail/pull/131#issue-244686818) this supports multiple activity types (playing, watching, listening and streaming). ### Removed - Removed the deprecated `status` command. +- This also means you will have to reset your bot status with the `activity` command as it will break. # v2.3.0 @@ -171,4 +174,4 @@ This release introduces the use of our centralized [API service](https://github. - Optional support for using a seperate guild as the operations center (#81) - NSFW Command to change channels to NSFW (#77) -# v0.0.0 \ No newline at end of file +# v0.0.0 From 0084158aa1b81bba5cee4dca0c879798368577da Mon Sep 17 00:00:00 2001 From: Kyber Date: Tue, 15 Jan 2019 18:21:13 +1100 Subject: [PATCH 8/9] Update bot.py --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index faf4998cc9..e6833c005a 100644 --- a/bot.py +++ b/bot.py @@ -22,7 +22,7 @@ SOFTWARE. """ -__version__ = '2.3.1' +__version__ = '2.4.0' import asyncio import textwrap From 2095f2c634701afcf675699c684e97da584468bd Mon Sep 17 00:00:00 2001 From: taaku251 <45324516+Taaku18@users.noreply.github.com> Date: Mon, 14 Jan 2019 23:31:24 -0800 Subject: [PATCH 9/9] Use commands.UserInputError instead of custom error message --- cogs/utility.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/cogs/utility.py b/cogs/utility.py index ffe93b8406..10f4c8884d 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -291,22 +291,12 @@ async def activity(self, ctx, activity_type: str, *, message: str = ''): return await ctx.send(embed=em) if not message: - em = discord.Embed( - title='Invalid Message', - description='You must set an activity message.', - color=discord.Color.red() - ) - return await ctx.send(embed=em) + raise commands.UserInputError try: activity_type = ActivityType[activity_type] except KeyError: - em = discord.Embed( - title='Invalid Activity Type', - description=f'Cannot set activity to: {activity_type}.', - color=discord.Color.red() - ) - return await ctx.send(embed=em) + raise commands.UserInputError url = 'https://www.twitch.tv/discord-modmail/' if activity_type == ActivityType.streaming else None activity = discord.Activity(type=activity_type, name=message, url=url)