Skip to content

Commit 169011c

Browse files
committed
Merge from master
2 parents adbbb85 + d93740c commit 169011c

File tree

11 files changed

+85
-328
lines changed

11 files changed

+85
-328
lines changed

CHANGELOG.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ A `?delete` command, which is an alternative to manually deleting a message. Thi
4545
When updating to this version, all prior permission settings with guild-based permissions will be invalidated. You will need to convert to the above system.
4646
`OWNERS` will also get removed, you will need to set owners through `?permissions add level owner 212931293123129` or any way listed above.
4747

48-
# v2.17.1
48+
49+
# v2.17.2
4950

5051
### Changed
5152

52-
- Stricter fallback genesis embed search. This update shouldn't affect anyone.
53+
- Logs search command will search through log keys as well now.
54+
- For example, `?logs search e7499e82f8ff`.
5355

54-
### Info
56+
# v2.17.1
57+
### What's new?
58+
59+
Stricter fallback genesis embed search.
60+
61+
### Changed
5562
How modmail checks if a channel is a thread:
5663

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

8087
# v2.16.0
8188

82-
### What's new?
89+
### Changed
90+
91+
All support for Modmail API (api.modmail.tk) has terminated.
92+
If you're still using api.modmail.tk, you will need to migrate to the self-hosted database
93+
option ASAP. Your bot will not work unless you switch to the self-hosted option. Refer to the
94+
installation tutorial for information regarding self-hosted Modmail.
8395

8496
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.
8597

98+
# v2.15.1
99+
100+
### Fixed
101+
102+
Emergency patch of a SyntaxError.
103+
86104
# v2.15.0
87105

88106
### What's new?
@@ -270,7 +288,7 @@ Huge thanks to Sasiko for reporting these issues.
270288

271289
# v2.12.0
272290

273-
### Important
291+
### Important
274292
**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.
275293
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.**
276294

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: 18 additions & 87 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, PermissionLevel
@@ -103,14 +104,10 @@ def __init__(self):
103104

104105
self._configure_logging()
105106

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

113-
self.data_task = self.loop.create_task(self.data_loop())
114111
self.autoupdate_task = self.loop.create_task(self.autoupdate_loop())
115112
self._load_extensions()
116113
self.owner = None
@@ -143,10 +140,6 @@ def version(self):
143140
def db(self):
144141
return self._db
145142

146-
@property
147-
def self_hosted(self):
148-
return bool(self.config.get('mongo_uri', ''))
149-
150143
@property
151144
def api(self):
152145
return self._api
@@ -204,12 +197,6 @@ def run(self, *args, **kwargs):
204197
except Exception:
205198
logger.critical(error('Fatal exception'), exc_info=True)
206199
finally:
207-
try:
208-
self.data_task.cancel()
209-
self.loop.run_until_complete(self.data_task)
210-
except asyncio.CancelledError:
211-
logger.debug('data_task has been cancelled')
212-
213200
try:
214201
self.autoupdate_task.cancel()
215202
self.loop.run_until_complete(self.autoupdate_task)
@@ -339,15 +326,8 @@ def main_color(self):
339326

340327
async def on_connect(self):
341328
logger.info(LINE)
342-
if not self.self_hosted:
343-
logger.info(info('MODE: Using the Modmail API'))
344-
logger.info(LINE)
345-
await self.validate_api_token()
346-
logger.info(LINE)
347-
else:
348-
logger.info(info('Mode: Self-hosting logs.'))
349-
await self.validate_database_connection()
350-
logger.info(LINE)
329+
await self.validate_database_connection()
330+
logger.info(LINE)
351331
logger.info(info('Connected to gateway.'))
352332

353333
await self.config.refresh()
@@ -358,12 +338,12 @@ async def on_connect(self):
358338
async def setup_indexes(self):
359339
"""Setup text indexes so we can use the $search operator"""
360340
coll = self.db.logs
361-
index_name = 'messages.content_text_messages.author.name_text'
341+
index_name = 'messages.content_text_messages.author.name_text_key_text'
362342

363343
index_info = await coll.index_information()
364344

365345
# Backwards compatibility
366-
old_index = 'messages.content_text'
346+
old_index = 'messages.content_text_messages.author.name_text'
367347
if old_index in index_info:
368348
logger.info(info(f'Dropping old index: {old_index}'))
369349
await coll.drop_index(old_index)
@@ -373,7 +353,8 @@ async def setup_indexes(self):
373353
logger.info(info('Name: ' + index_name))
374354
await coll.create_index([
375355
('messages.content', 'text'),
376-
('messages.author.name', 'text')
356+
('messages.author.name', 'text'),
357+
('key', 'text')
377358
])
378359

379360
async def on_ready(self):
@@ -823,32 +804,6 @@ def overwrites(ctx):
823804
)
824805
return overwrites
825806

826-
async def validate_api_token(self):
827-
try:
828-
self.config.modmail_api_token
829-
except KeyError:
830-
logger.critical(error(f'MODMAIL_API_TOKEN not found.'))
831-
logger.critical(error('Set a config variable called '
832-
'MODMAIL_API_TOKEN with a token from '
833-
'https://dashboard.modmail.tk.'))
834-
logger.critical(error('If you want to self-host logs, '
835-
'input a MONGO_URI config variable.'))
836-
logger.critical(error('A Modmail API token is not needed '
837-
'if you are self-hosting logs.'))
838-
839-
return await self.logout()
840-
else:
841-
valid = await self.api.validate_token()
842-
if not valid:
843-
logger.critical(error('Invalid MODMAIL_API_TOKEN - get one '
844-
'from https://dashboard.modmail.tk'))
845-
return await self.logout()
846-
847-
user = await self.api.get_user_info()
848-
username = user['user']['username']
849-
logger.info(info('Validated token.'))
850-
logger.info(info('GitHub user: ' + username))
851-
852807
async def validate_database_connection(self):
853808
try:
854809
await self.db.command('buildinfo')
@@ -860,32 +815,6 @@ async def validate_database_connection(self):
860815
else:
861816
logger.info(info('Successfully connected to the database.'))
862817

863-
async def data_loop(self):
864-
await self.wait_until_ready()
865-
self.owner = (await self.application_info()).owner
866-
867-
while not self.is_closed():
868-
data = {
869-
"owner_name": str(self.owner),
870-
"owner_id": self.owner.id,
871-
"bot_id": self.user.id,
872-
"bot_name": str(self.user),
873-
"avatar_url": self.user.avatar_url,
874-
"guild_id": self.guild_id,
875-
"guild_name": self.guild.name,
876-
"member_count": len(self.guild.members),
877-
"uptime": (datetime.utcnow() -
878-
self.start_time).total_seconds(),
879-
"latency": f'{self.ws.latency * 1000:.4f}',
880-
"version": self.version,
881-
# TODO: change to `self_hosted`
882-
"selfhosted": self.self_hosted,
883-
"last_updated": str(datetime.utcnow())
884-
}
885-
886-
await self.api.post_metadata(data)
887-
await asyncio.sleep(3600)
888-
889818
async def autoupdate_loop(self):
890819
await self.wait_until_ready()
891820

@@ -894,16 +823,19 @@ async def autoupdate_loop(self):
894823
logger.info(LINE)
895824
return
896825

897-
if self.self_hosted and not self.config.get('github_access_token'):
826+
if not self.config.get('github_access_token'):
898827
logger.warning(info('GitHub access token not found.'))
899828
logger.warning(info('Autoupdates disabled.'))
900829
logger.info(LINE)
901830
return
902831

832+
logger.info(info('Autoupdate loop started.'))
833+
903834
while not self.is_closed():
904-
metadata = await self.api.get_metadata()
835+
changelog = await Changelog.from_url(self)
836+
latest = changelog.latest_version
905837

906-
if metadata['latest_version'] != self.version:
838+
if parse_version(self.version) < parse_version(latest.version):
907839
data = await self.api.update_repository()
908840

909841
embed = discord.Embed(color=discord.Color.green())
@@ -913,11 +845,10 @@ async def autoupdate_loop(self):
913845
embed.set_author(name=user['username'] + ' - Updating Bot',
914846
icon_url=user['avatar_url'],
915847
url=user['url'])
848+
916849
embed.set_footer(text=f'Updating Modmail v{self.version} '
917-
f"-> v{metadata['latest_version']}")
850+
f'-> v{latest.version}')
918851

919-
changelog = await Changelog.from_url(self)
920-
latest = changelog.latest_version
921852
embed.description = latest.description
922853
for name, value in latest.fields.items():
923854
embed.add_field(name=name, value=value)

cogs/modmail.py

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

381381
created_at = parser.parse(entry['created_at'])
382382

383-
log_url = (
384-
f"https://logs.modmail.tk/{key}"
385-
if not self.bot.self_hosted else
386-
self.bot.config.log_url.strip('/') + f'/logs/{key}'
387-
)
383+
log_url = self.bot.config.log_url.strip('/') + f'/logs/{key}'
388384

389385
username = entry['recipient']['name'] + '#'
390386
username += entry['recipient']['discriminator']
@@ -451,14 +447,6 @@ async def logs(self, ctx, *, member: User = None):
451447
@checks.has_permissions(PermissionLevel.SUPPORTER)
452448
async def closed_by(self, ctx, *, user: User = None):
453449
"""Returns all logs closed by a user."""
454-
if not self.bot.self_hosted:
455-
embed = discord.Embed(
456-
color=discord.Color.red(),
457-
description='This command only works if '
458-
'you are self-hosting your logs.'
459-
)
460-
return await ctx.send(embed=embed)
461-
462450
user = user or ctx.author
463451

464452
query = {
@@ -493,14 +481,6 @@ async def search(self, ctx, limit: Optional[int] = None, *, query):
493481

494482
await ctx.trigger_typing()
495483

496-
if not self.bot.self_hosted:
497-
embed = discord.Embed(
498-
color=discord.Color.red(),
499-
description='This command only works if you '
500-
'are self-hosting your logs.'
501-
)
502-
return await ctx.send(embed=embed)
503-
504484
query = {
505485
'guild_id': str(self.bot.guild_id),
506486
'open': False,

0 commit comments

Comments
 (0)