mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-14 18:11:23 +01:00
Add posting status for discordbots.org
This commit is contained in:
parent
01e1412af1
commit
71097eca8b
@ -5,5 +5,7 @@ config = {
|
||||
|
||||
'redis-uri': "redis://",
|
||||
|
||||
'discord-bots-org-token': "DiscordBots.org Post Stats Token",
|
||||
|
||||
'logging-location': "/home/titan/Titan/discordbot/titanbot.log",
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ from config import config
|
||||
from titanembeds.database import DatabaseInterface
|
||||
from titanembeds.commands import Commands
|
||||
from titanembeds.socketio import SocketIOInterface
|
||||
from titanembeds.poststats import DiscordBotsOrg
|
||||
from collections import deque
|
||||
import discord
|
||||
import aiohttp
|
||||
@ -25,6 +26,8 @@ class Titan(discord.Client):
|
||||
|
||||
self.delete_list = [] # List of msg ids to prevent duplicate delete
|
||||
|
||||
self.discordBotsOrg = None
|
||||
|
||||
def _cleanup(self):
|
||||
try:
|
||||
self.loop.run_until_complete(self.logout())
|
||||
@ -92,6 +95,9 @@ class Titan(discord.Client):
|
||||
else:
|
||||
print("Skipping indexing server due to no-init flag")
|
||||
|
||||
self.discordBotsOrg = DiscordBotsOrg(self.user.id, config.get("discord-bots-org-token", None))
|
||||
await self.discordBotsOrg.post(len(self.servers))
|
||||
|
||||
async def on_message(self, message):
|
||||
await self.database.push_message(message)
|
||||
await self.socketio.on_message(message)
|
||||
@ -128,9 +134,11 @@ class Titan(discord.Client):
|
||||
continue
|
||||
async for message in self.logs_from(channel, limit=50, reverse=True):
|
||||
await self.database.push_message(message)
|
||||
await self.discordBotsOrg.post(len(self.servers))
|
||||
|
||||
async def on_server_remove(self, guild):
|
||||
await self.database.remove_guild(guild)
|
||||
await self.discordBotsOrg.post(len(self.servers))
|
||||
|
||||
async def on_server_update(self, guildbefore, guildafter):
|
||||
await self.database.update_guild(guildafter)
|
||||
|
12
discordbot/titanembeds/poststats.py
Normal file
12
discordbot/titanembeds/poststats.py
Normal file
@ -0,0 +1,12 @@
|
||||
import aiohttp
|
||||
|
||||
class DiscordBotsOrg(): # https://discordbots.org
|
||||
def __init__(self, client_id, token):
|
||||
self.url = "https://discordbots.org/api/bots/{}/stats".format(client_id)
|
||||
self.token = token
|
||||
|
||||
async def post(self, count):
|
||||
headers = {"Authorization": self.token}
|
||||
payload = {"server_count": count}
|
||||
async with aiohttp.ClientSession() as aioclient:
|
||||
await aioclient.post(self.url, data=payload, headers=headers)
|
Loading…
Reference in New Issue
Block a user