Skip to content
Browse files

Stats webhooks added

  • Loading branch information...
MrSpinne committed Aug 31, 2019
1 parent ddb56ba commit ccaa0452288e275004df126a841f0b65c18ad292
Showing with 63 additions and 17 deletions.
  1. +7 −2 data/config.ini
  2. +52 −11 extensions/
  3. +2 −1 requirements.txt
  4. +2 −3
@@ -28,8 +28,13 @@ private_key_id =
api_key =
app_key =

[Botlist] # optional
discordbots =
[Discordbots] # optional
api_key =
webhook_auth =
webhook_path =
webhook_port =

[Botlists] # optional
divinediscordbots =
discordbotreviews =
mythicalbots =
@@ -16,8 +16,9 @@
along with this program. If not, see <>.

from discord.ext import commands
from discord.ext import commands, tasks
from datadog import initialize, statsd
import dbl

class Stats(commands.Cog):
@@ -36,9 +37,16 @@ class Stats(commands.Cog):
Datadog api key to post events to.
dd_app_key: :obj:`str`
Datadog app key to post events to.
bl_discordbots: :obj:`str`
dbl: :obj:`dbl.Client`
DiscordBots client. This is `None` if no configuration found.
dbl_api_key: :obj:`str`
Api key for to post stats to.
Also used to enabled vote locking.
dbl_webhook_auth: :obj:`str`
Webhook authorization for
dbl_webhook_path: :obj:`str`
Path of the webhook to use for
dbl_webhook_port: :obj:`str`
Port to use the webhook for on.
bl_divinediscordbots: :obj:`str`
Api key for to post stats to.
bl_discordbotreviews: :obj:`str`
@@ -58,7 +66,13 @@ def __init__(self, bot): = bot
self.dd_api_key ="datadog", "api_key")
self.dd_app_key ="datadog", "app_key")
self.bl_discordbots ="botlists", "discordbots")

self.dbl = None
self.dbl_api_key ="discordbots", "api_key")
self.dbl_webhook_auth ="discordbots", "webhook_auth")
self.dbl_webhook_path ="discordbots", "webhook_path")
self.dbl_webhook_port ="discordbots", "webhook_port")

self.bl_divinediscordbots ="botlists", "divinediscordbots")
self.bl_discordbotreviews ="botlists", "discordbotreviews")
self.bl_mythicalbots ="botlists", "mythicalbots")
@@ -67,7 +81,7 @@ def __init__(self, bot):
self.bl_botsondiscord ="botlists", "botsondiscord")


def init_datadog(self):
"""Initialize connection to Datadog to post metrics to and add event listener.
@@ -78,7 +92,7 @@ def init_datadog(self):
The `on_socket_response` event is called on any event.
if self.dd_api_key != "" and self.dd_app_key != "":
if self.dd_api_key and self.dd_app_key:
initialize(self.dd_api_key, self.dd_app_key), "on_socket_response")

@@ -95,11 +109,38 @@ def init_datadog(self):
event = payload.get("t")

def init_bot_lists(self):
"""Initialize stats posting to the bot lists. This will also setup vote recognition.
def init_discordbots(self):
"""Initialize stats posting to the bot lists and vote recognition.
This also registers a webhook to track votes.
If DiscordBot credentials are not set, then it will be disabled.
if self.dbl_api_key:
credentials = {"token": self.dbl_api_key,
"autopost": True,
"webhook_auth": self.dbl_webhook_auth,
"webhook_path": self.dbl_webhook_path,
"webhook_port": self.dbl_webhook_port}
self.dbl = dbl.Client(**credentials)

async def on_dbl_test(self, data):
"""Track votes from and save it to database.
This is automatically called by the event handler.
data: :obj:`dict`
Data with vote info.
# TODO: Register vote to db

Only bot lists with credentials will be initialized.
If DiscordBot credentials are not set then vote locking will be disabled.
async def post_bot_lists(self):
"""Post bot stats to the bot lists which have been configured.

@@ -110,7 +151,7 @@ def setup(bot):
bot: :class:`commands.AutoShardedBot`
bot: :class:`discord.ext.commands.AutoShardedBot`
@@ -13,4 +13,5 @@ aiohttp
@@ -26,7 +26,6 @@ def __init__(self):
signal.signal(signal.SIGTERM, self.shutdown)
self.db_connector, self.db_cursor, self.app_info, self.gspread, self.config = None, None, None, None, {}
self.sentry, self.lavalink, self.dbl, self.statposter, self.anilist = sentry_sdk, None, None, None, Pymoe.Anilist()

def get_config(self, option, key):
"""Get config value"""
@@ -36,7 +35,7 @@ def get_config(self, option, key):
config = configparser.ConfigParser()"data/config.ini")
return config.get(option.lower(), key)
return config.get(option.capitalize(), key)

async def on_ready(self):
"""Get ready and start"""
@@ -376,4 +375,4 @@ def edit_song(self, song_id, setting, value):
if __name__ == "__main__":
shiro = Shiro()["discord"]["token"])"discord", "token"))

0 comments on commit ccaa045

Please sign in to comment.
You can’t perform that action at this time.