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://",
|
'redis-uri': "redis://",
|
||||||
|
|
||||||
|
'discord-bots-org-token': "DiscordBots.org Post Stats Token",
|
||||||
|
|
||||||
'logging-location': "/home/titan/Titan/discordbot/titanbot.log",
|
'logging-location': "/home/titan/Titan/discordbot/titanbot.log",
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ from config import config
|
|||||||
from titanembeds.database import DatabaseInterface
|
from titanembeds.database import DatabaseInterface
|
||||||
from titanembeds.commands import Commands
|
from titanembeds.commands import Commands
|
||||||
from titanembeds.socketio import SocketIOInterface
|
from titanembeds.socketio import SocketIOInterface
|
||||||
|
from titanembeds.poststats import DiscordBotsOrg
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import discord
|
import discord
|
||||||
import aiohttp
|
import aiohttp
|
||||||
@ -24,6 +25,8 @@ class Titan(discord.Client):
|
|||||||
self.socketio = SocketIOInterface(self, config["redis-uri"])
|
self.socketio = SocketIOInterface(self, config["redis-uri"])
|
||||||
|
|
||||||
self.delete_list = [] # List of msg ids to prevent duplicate delete
|
self.delete_list = [] # List of msg ids to prevent duplicate delete
|
||||||
|
|
||||||
|
self.discordBotsOrg = None
|
||||||
|
|
||||||
def _cleanup(self):
|
def _cleanup(self):
|
||||||
try:
|
try:
|
||||||
@ -91,6 +94,9 @@ class Titan(discord.Client):
|
|||||||
await self.database.remove_unused_guilds(self.servers)
|
await self.database.remove_unused_guilds(self.servers)
|
||||||
else:
|
else:
|
||||||
print("Skipping indexing server due to no-init flag")
|
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):
|
async def on_message(self, message):
|
||||||
await self.database.push_message(message)
|
await self.database.push_message(message)
|
||||||
@ -128,9 +134,11 @@ class Titan(discord.Client):
|
|||||||
continue
|
continue
|
||||||
async for message in self.logs_from(channel, limit=50, reverse=True):
|
async for message in self.logs_from(channel, limit=50, reverse=True):
|
||||||
await self.database.push_message(message)
|
await self.database.push_message(message)
|
||||||
|
await self.discordBotsOrg.post(len(self.servers))
|
||||||
|
|
||||||
async def on_server_remove(self, guild):
|
async def on_server_remove(self, guild):
|
||||||
await self.database.remove_guild(guild)
|
await self.database.remove_guild(guild)
|
||||||
|
await self.discordBotsOrg.post(len(self.servers))
|
||||||
|
|
||||||
async def on_server_update(self, guildbefore, guildafter):
|
async def on_server_update(self, guildbefore, guildafter):
|
||||||
await self.database.update_guild(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