diff --git a/discordbot/config.example.py b/discordbot/config.example.py index 228c259..d8c13b6 100644 --- a/discordbot/config.example.py +++ b/discordbot/config.example.py @@ -7,5 +7,7 @@ config = { 'discord-bots-org-token': "DiscordBots.org Post Stats Token", + 'bots-discord-pw-token': "bots.discord.pw Post Stats Token", + 'logging-location': "/home/titan/Titan/discordbot/titanbot.log", } diff --git a/discordbot/titanembeds/bot.py b/discordbot/titanembeds/bot.py index 0dc2d7e..952a2d8 100644 --- a/discordbot/titanembeds/bot.py +++ b/discordbot/titanembeds/bot.py @@ -2,7 +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 titanembeds.poststats import DiscordBotsOrg, BotsDiscordPw from collections import deque import discord import aiohttp @@ -27,6 +27,7 @@ class Titan(discord.Client): self.delete_list = [] # List of msg ids to prevent duplicate delete self.discordBotsOrg = None + self.botsDiscordPw = None def _cleanup(self): try: @@ -74,7 +75,8 @@ class Titan(discord.Client): return self.discordBotsOrg = DiscordBotsOrg(self.user.id, config.get("discord-bots-org-token", None)) - await self.discordBotsOrg.post(len(self.servers)) + self.botsDiscordPw = BotsDiscordPw(self.user.id, config.get("bots-discord-pw-token", None)) + await self.postStats() if "no-init" not in sys.argv: for server in self.servers: @@ -134,11 +136,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)) + await self.postStats() async def on_server_remove(self, guild): await self.database.remove_guild(guild) - await self.discordBotsOrg.post(len(self.servers)) + await self.postStats() async def on_server_update(self, guildbefore, guildafter): await self.database.update_guild(guildafter) @@ -240,3 +242,8 @@ class Titan(discord.Client): if msg.id == msg_id: return True return False + + async def postStats(self): + count = len(self.servers) + await self.discordBotsOrg.post(count) + await self.botsDiscordPw.post(count) diff --git a/discordbot/titanembeds/poststats.py b/discordbot/titanembeds/poststats.py index 50568e3..e19c7d9 100644 --- a/discordbot/titanembeds/poststats.py +++ b/discordbot/titanembeds/poststats.py @@ -1,4 +1,5 @@ import aiohttp +import json class DiscordBotsOrg(): # https://discordbots.org def __init__(self, client_id, token): @@ -9,4 +10,15 @@ class DiscordBotsOrg(): # https://discordbots.org headers = {"Authorization": self.token} payload = {"server_count": count} async with aiohttp.ClientSession() as aioclient: - await aioclient.post(self.url, data=payload, headers=headers) \ No newline at end of file + await aioclient.post(self.url, data=payload, headers=headers) + +class BotsDiscordPw(): # https://bots.discord.pw/ + def __init__(self, client_id, token): + self.url = "https://bots.discord.pw/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: + t = await aioclient.post(self.url, json=payload, headers=headers) \ No newline at end of file