Skip to content

Added activity command for Issue #116 #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ ENV/
# mypy
.mypy_cache/
*.json
!app.json

#Pycharm
.idea/

#MacOs
.DS_Store

config.json
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ 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.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) 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

### Added
Expand Down Expand Up @@ -162,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
# v0.0.0
14 changes: 10 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SOFTWARE.
"""

__version__ = '2.3.0'
__version__ = '2.4.0'

import asyncio
import textwrap
Expand All @@ -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
Expand Down Expand Up @@ -175,9 +176,14 @@ 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:
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):
"""Bot startup, sets uptime."""
Expand Down
2 changes: 1 addition & 1 deletion cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import datetime
from typing import Optional, Union
import re

import discord
from discord.ext import commands

import dateutil.parser

from core.decorators import trigger_typing
Expand Down
52 changes: 37 additions & 15 deletions cogs/utility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import discord
from discord.ext import commands
from discord.enums import ActivityType

import datetime
import traceback
import inspect
Expand Down Expand Up @@ -265,30 +267,50 @@ async def update(self, ctx):
else:
em.description = 'Already up to date with master repository.'


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 activity(self, ctx, activity_type: str, *, message: str = ''):
"""
Set a custom activity for the bot.

Possible activity types: `playing`, `streaming`, `listening`, `watching`, `clear`

if message == 'clear':
self.bot.config['status'] = None
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 await self.bot.change_presence(activity=None)
em = discord.Embed(
title='Activity Removed',
color=discord.Color.green()
)
return await ctx.send(embed=em)

if not message:
raise commands.UserInputError

await self.bot.change_presence(activity=discord.Game(message))
self.bot.config['status'] = message
try:
activity_type = ActivityType[activity_type]
except KeyError:
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)
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()
await ctx.send(embed=em)
em = discord.Embed(
title='Activity Changed',
description=f'Current activity is: {activity_type.name} {message}.',
color=discord.Color.green()
)
return await ctx.send(embed=em)

@commands.command()
@trigger_typing
Expand Down