Skip to content

Commit e0cf2a7

Browse files
authored
Merge pull request #131 from Taaku18/master
Added `activity` command for Issue #116
2 parents 81f1b79 + 2095f2c commit e0cf2a7

File tree

5 files changed

+67
-21
lines changed

5 files changed

+67
-21
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ ENV/
100100
# mypy
101101
.mypy_cache/
102102
*.json
103+
!app.json
103104

105+
#Pycharm
106+
.idea/
107+
108+
#MacOs
109+
.DS_Store
104110

105111
config.json

CHANGELOG.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77

8+
# v2.4.0
9+
10+
Breaking changes for bot status.
11+
12+
### Added
13+
- Added the `activity` command for setting the activity
14+
- [PR #131](https://github.com/kyb3r/modmail/pull/131#issue-244686818) this supports multiple activity types (playing, watching, listening and streaming).
15+
16+
### Removed
17+
- Removed the deprecated `status` command.
18+
- This also means you will have to reset your bot status with the `activity` command as it will break.
19+
820
# v2.3.0
921

1022
### Added
@@ -162,4 +174,4 @@ This release introduces the use of our centralized [API service](https://github.
162174
- Optional support for using a seperate guild as the operations center (#81)
163175
- NSFW Command to change channels to NSFW (#77)
164176

165-
# v0.0.0
177+
# v0.0.0

bot.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
"""
2424

25-
__version__ = '2.3.0'
25+
__version__ = '2.4.0'
2626

2727
import asyncio
2828
import textwrap
@@ -33,6 +33,7 @@
3333

3434
import discord
3535
import aiohttp
36+
from discord.enums import ActivityType
3637
from discord.ext import commands
3738
from discord.ext.commands.view import StringView
3839
from motor.motor_asyncio import AsyncIOMotorClient
@@ -175,9 +176,14 @@ async def on_connect(self):
175176
print(line)
176177
print(Fore.CYAN + 'Connected to gateway.')
177178
await self.config.refresh()
178-
status = self.config.get('status')
179-
if status:
180-
await self.change_presence(activity=discord.Game(status))
179+
180+
activity_type = self.config.get('activity_type')
181+
message = self.config.get('activity_message')
182+
if activity_type and message:
183+
url = 'https://www.twitch.tv/discord-modmail/' if activity_type == ActivityType.streaming else None
184+
activity = discord.Activity(type=activity_type, name=message,
185+
url=url)
186+
await self.change_presence(activity=activity)
181187

182188
async def on_ready(self):
183189
"""Bot startup, sets uptime."""

cogs/modmail.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import datetime
44
from typing import Optional, Union
5-
import re
65

76
import discord
87
from discord.ext import commands
8+
99
import dateutil.parser
1010

1111
from core.decorators import trigger_typing

cogs/utility.py

+37-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import discord
22
from discord.ext import commands
3+
from discord.enums import ActivityType
4+
35
import datetime
46
import traceback
57
import inspect
@@ -265,30 +267,50 @@ async def update(self, ctx):
265267
else:
266268
em.description = 'Already up to date with master repository.'
267269

268-
269270
await ctx.send(embed=em)
270271

271-
@commands.command(name='status', aliases=['customstatus', 'presence'])
272+
@commands.command(aliases=['presence'])
272273
@commands.has_permissions(administrator=True)
273-
async def _status(self, ctx, *, message):
274-
"""Set a custom playing status for the bot.
275-
276-
Set the message to `clear` if you want to remove the playing status.
274+
async def activity(self, ctx, activity_type: str, *, message: str = ''):
277275
"""
276+
Set a custom activity for the bot.
277+
278+
Possible activity types: `playing`, `streaming`, `listening`, `watching`, `clear`
278279
279-
if message == 'clear':
280-
self.bot.config['status'] = None
280+
When activity type is set to `clear`, the current activity is removed.
281+
"""
282+
if activity_type == 'clear':
283+
await self.bot.change_presence(activity=None)
284+
self.bot.config['activity_type'] = None
285+
self.bot.config['activity_message'] = None
281286
await self.bot.config.update()
282-
return await self.bot.change_presence(activity=None)
287+
em = discord.Embed(
288+
title='Activity Removed',
289+
color=discord.Color.green()
290+
)
291+
return await ctx.send(embed=em)
292+
293+
if not message:
294+
raise commands.UserInputError
283295

284-
await self.bot.change_presence(activity=discord.Game(message))
285-
self.bot.config['status'] = message
296+
try:
297+
activity_type = ActivityType[activity_type]
298+
except KeyError:
299+
raise commands.UserInputError
300+
301+
url = 'https://www.twitch.tv/discord-modmail/' if activity_type == ActivityType.streaming else None
302+
activity = discord.Activity(type=activity_type, name=message, url=url)
303+
await self.bot.change_presence(activity=activity)
304+
self.bot.config['activity_type'] = activity_type
305+
self.bot.config['activity_message'] = message
286306
await self.bot.config.update()
287307

288-
em = discord.Embed(title='Status Changed')
289-
em.description = message
290-
em.color = discord.Color.green()
291-
await ctx.send(embed=em)
308+
em = discord.Embed(
309+
title='Activity Changed',
310+
description=f'Current activity is: {activity_type.name} {message}.',
311+
color=discord.Color.green()
312+
)
313+
return await ctx.send(embed=em)
292314

293315
@commands.command()
294316
@trigger_typing

0 commit comments

Comments
 (0)