Skip to content

Commit 6dce77b

Browse files
authored
Remove reliability on Modmail API (#219)
* Remove modmail.tk link in changelog * Removed api * Remove instance from readme, and other references * Bump version 2.16.0
1 parent 022407e commit 6dce77b

File tree

11 files changed

+76
-330
lines changed

11 files changed

+76
-330
lines changed

CHANGELOG.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Changed
1010

1111
- Logs search command will search through log keys as well now.
12-
13-
e.g. `?logs search e7499e82f8ff`
12+
- For example, `?logs search e7499e82f8ff`.
1413

1514
# v2.17.1
15+
### What's new?
1616

17-
### Changed
18-
19-
- Stricter fallback genesis embed search. This update shouldn't affect anyone.
17+
Stricter fallback genesis embed search.
2018

21-
### Info
19+
### Changed
2220
How modmail checks if a channel is a thread:
2321

2422
1. First the bot checks if the channel topic is in the format `User ID: xxxx`, this means it is a thread.
@@ -46,10 +44,21 @@ An issue where a scheduled close would not execute over a long period of time if
4644

4745
# v2.16.0
4846

49-
### What's new?
47+
### Changed
48+
49+
All support for Modmail API (api.modmail.tk) has terminated.
50+
If you're still using api.modmail.tk, you will need to migrate to the self-hosted database
51+
option ASAP. Your bot will not work unless you switch to the self-hosted option. Refer to the
52+
installation tutorial for information regarding self-hosted Modmail.
5053

5154
If a member leaves/joins (again) while they are a recipient of a thread, a message will be sent to notify you that this has occured.
5255

56+
# v2.15.1
57+
58+
### Fixed
59+
60+
Emergency patch of a SyntaxError.
61+
5362
# v2.15.0
5463

5564
### What's new?
@@ -237,7 +246,7 @@ Huge thanks to Sasiko for reporting these issues.
237246

238247
# v2.12.0
239248

240-
### Important
249+
### Important
241250
**In the future, the Modmail API (https://modmail.tk) will be deprecated. This is due to the fact that we are providing a free service without getting anything in return, and thus we do not have the resources to scale to accommodate for more users.
242251
We recommend using your own database for logs. In the future you will soon get a `backup` command so you can download all your pre-existing data and migrate to your own database.**
243252

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
<img src="https://img.shields.io/discord/515071617815019520.svg?style=for-the-badge&colorB=7289DA" alt="Support">
1414
</a>
1515

16-
<a href="https://github.com/kyb3r/modmail/">
17-
<img src="https://api.modmail.tk/badges/instances.svg" alt="Bot instances">
18-
</a>
19-
2016
<a href="https://patreon.com/kyber">
2117
<img src="https://img.shields.io/badge/patreon-donate-orange.svg?style=for-the-badge" alt="Python 3.7">
2218
</a>
@@ -56,8 +52,7 @@ Have you sent something with the `?reply` command by accident? Don't fret, you c
5652

5753
## Thread Logs
5854

59-
Thread conversations are automatically logged with a generated viewable website of the complete thread. Logs are rendered with styled HTML and presented in an aesthetically pleasing way—it blends seamlessly with the mobile version of Discord. An example of a logged conversation: https://logs.modmail.tk/02032d65a6f3
60-
55+
Thread conversations are automatically logged with a generated viewable website of the complete thread. Logs are rendered with styled HTML and presented in an aesthetically pleasing way—it blends seamlessly with the mobile version of Discord. An example of a logged conversation: https://modmail-logs.herokuapp.com/logs/02032d65a6f3.
6156

6257
# Contributing
6358

bot.py

Lines changed: 13 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import sys
3232

3333
from datetime import datetime
34+
from pkg_resources import parse_version
3435
from types import SimpleNamespace
3536

3637
import discord
@@ -45,7 +46,7 @@
4546
from motor.motor_asyncio import AsyncIOMotorClient
4647

4748
from core.changelog import Changelog
48-
from core.clients import ModmailApiClient, SelfHostedClient, PluginDatabaseClient
49+
from core.clients import SelfHostedClient, PluginDatabaseClient
4950
from core.config import ConfigManager
5051
from core.utils import info, error
5152
from core.models import Bot
@@ -104,14 +105,10 @@ def __init__(self):
104105

105106
self._configure_logging()
106107

107-
if self.self_hosted:
108-
self._db = AsyncIOMotorClient(self.config.mongo_uri).modmail_bot
109-
self._api = SelfHostedClient(self)
110-
else:
111-
self._api = ModmailApiClient(self)
108+
self._db = AsyncIOMotorClient(self.config.mongo_uri).modmail_bot
109+
self._api = SelfHostedClient(self)
112110
self.plugin_db = PluginDatabaseClient(self)
113111

114-
self.data_task = self.loop.create_task(self.data_loop())
115112
self.autoupdate_task = self.loop.create_task(self.autoupdate_loop())
116113
self._load_extensions()
117114
self.owner = None
@@ -144,10 +141,6 @@ def version(self):
144141
def db(self):
145142
return self._db
146143

147-
@property
148-
def self_hosted(self):
149-
return bool(self.config.get('mongo_uri', ''))
150-
151144
@property
152145
def api(self):
153146
return self._api
@@ -210,12 +203,6 @@ def run(self, *args, **kwargs):
210203
except Exception:
211204
logger.critical(error('Fatal exception'), exc_info=True)
212205
finally:
213-
try:
214-
self.data_task.cancel()
215-
self.loop.run_until_complete(self.data_task)
216-
except asyncio.CancelledError:
217-
logger.debug('data_task has been cancelled')
218-
219206
try:
220207
self.autoupdate_task.cancel()
221208
self.loop.run_until_complete(self.autoupdate_task)
@@ -345,15 +332,8 @@ def main_color(self):
345332

346333
async def on_connect(self):
347334
logger.info(LINE)
348-
if not self.self_hosted:
349-
logger.info(info('MODE: Using the Modmail API'))
350-
logger.info(LINE)
351-
await self.validate_api_token()
352-
logger.info(LINE)
353-
else:
354-
logger.info(info('Mode: Self-hosting logs.'))
355-
await self.validate_database_connection()
356-
logger.info(LINE)
335+
await self.validate_database_connection()
336+
logger.info(LINE)
357337
logger.info(info('Connected to gateway.'))
358338

359339
await self.config.refresh()
@@ -806,32 +786,6 @@ def overwrites(ctx):
806786
)
807787
return overwrites
808788

809-
async def validate_api_token(self):
810-
try:
811-
self.config.modmail_api_token
812-
except KeyError:
813-
logger.critical(error(f'MODMAIL_API_TOKEN not found.'))
814-
logger.critical(error('Set a config variable called '
815-
'MODMAIL_API_TOKEN with a token from '
816-
'https://dashboard.modmail.tk.'))
817-
logger.critical(error('If you want to self-host logs, '
818-
'input a MONGO_URI config variable.'))
819-
logger.critical(error('A Modmail API token is not needed '
820-
'if you are self-hosting logs.'))
821-
822-
return await self.logout()
823-
else:
824-
valid = await self.api.validate_token()
825-
if not valid:
826-
logger.critical(error('Invalid MODMAIL_API_TOKEN - get one '
827-
'from https://dashboard.modmail.tk'))
828-
return await self.logout()
829-
830-
user = await self.api.get_user_info()
831-
username = user['user']['username']
832-
logger.info(info('Validated token.'))
833-
logger.info(info('GitHub user: ' + username))
834-
835789
async def validate_database_connection(self):
836790
try:
837791
await self.db.command('buildinfo')
@@ -843,32 +797,6 @@ async def validate_database_connection(self):
843797
else:
844798
logger.info(info('Successfully connected to the database.'))
845799

846-
async def data_loop(self):
847-
await self.wait_until_ready()
848-
self.owner = (await self.application_info()).owner
849-
850-
while not self.is_closed():
851-
data = {
852-
"owner_name": str(self.owner),
853-
"owner_id": self.owner.id,
854-
"bot_id": self.user.id,
855-
"bot_name": str(self.user),
856-
"avatar_url": self.user.avatar_url,
857-
"guild_id": self.guild_id,
858-
"guild_name": self.guild.name,
859-
"member_count": len(self.guild.members),
860-
"uptime": (datetime.utcnow() -
861-
self.start_time).total_seconds(),
862-
"latency": f'{self.ws.latency * 1000:.4f}',
863-
"version": self.version,
864-
# TODO: change to `self_hosted`
865-
"selfhosted": self.self_hosted,
866-
"last_updated": str(datetime.utcnow())
867-
}
868-
869-
await self.api.post_metadata(data)
870-
await asyncio.sleep(3600)
871-
872800
async def autoupdate_loop(self):
873801
await self.wait_until_ready()
874802

@@ -877,16 +805,19 @@ async def autoupdate_loop(self):
877805
logger.info(LINE)
878806
return
879807

880-
if self.self_hosted and not self.config.get('github_access_token'):
808+
if not self.config.get('github_access_token'):
881809
logger.warning(info('GitHub access token not found.'))
882810
logger.warning(info('Autoupdates disabled.'))
883811
logger.info(LINE)
884812
return
885813

814+
logger.info(info('Autoupdate loop started.'))
815+
886816
while not self.is_closed():
887-
metadata = await self.api.get_metadata()
817+
changelog = await Changelog.from_url(self)
818+
latest = changelog.latest_version
888819

889-
if metadata['latest_version'] != self.version:
820+
if parse_version(self.version) < parse_version(latest.version):
890821
data = await self.api.update_repository()
891822

892823
embed = discord.Embed(color=discord.Color.green())
@@ -897,10 +828,8 @@ async def autoupdate_loop(self):
897828
icon_url=user['avatar_url'],
898829
url=user['url'])
899830
embed.set_footer(text=f"Updating Modmail v{self.version} "
900-
f"-> v{metadata['latest_version']}")
831+
f"-> v{latest.version}")
901832

902-
changelog = await Changelog.from_url(self)
903-
latest = changelog.latest_version
904833
embed.description = latest.description
905834
for name, value in latest.fields.items():
906835
embed.add_field(name=name, value=value)

cogs/modmail.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,7 @@ def format_log_embeds(self, logs, avatar_url):
372372

373373
created_at = parser.parse(entry['created_at'])
374374

375-
log_url = (
376-
f"https://logs.modmail.tk/{key}"
377-
if not self.bot.self_hosted else
378-
self.bot.config.log_url.strip('/') + f'/logs/{key}'
379-
)
375+
log_url = self.bot.config.log_url.strip('/') + f'/logs/{key}'
380376

381377
username = entry['recipient']['name'] + '#'
382378
username += entry['recipient']['discriminator']
@@ -443,14 +439,6 @@ async def logs(self, ctx, *, member: User = None):
443439
@checks.has_permissions(manage_messages=True)
444440
async def closed_by(self, ctx, *, user: User = None):
445441
"""Returns all logs closed by a user."""
446-
if not self.bot.self_hosted:
447-
embed = discord.Embed(
448-
color=discord.Color.red(),
449-
description='This command only works if '
450-
'you are self-hosting your logs.'
451-
)
452-
return await ctx.send(embed=embed)
453-
454442
user = user or ctx.author
455443

456444
query = {
@@ -485,14 +473,6 @@ async def search(self, ctx, limit: Optional[int] = None, *, query):
485473

486474
await ctx.trigger_typing()
487475

488-
if not self.bot.self_hosted:
489-
embed = discord.Embed(
490-
color=discord.Color.red(),
491-
description='This command only works if you '
492-
'are self-hosting your logs.'
493-
)
494-
return await ctx.send(embed=embed)
495-
496476
query = {
497477
'guild_id': str(self.bot.guild_id),
498478
'open': False,

0 commit comments

Comments
 (0)