1
0
Fork 0
mirror of https://github.com/uhIgnacio/EmoteManager.git synced 2024-08-15 02:23:13 +00:00

add command invocation metrics

This commit is contained in:
io mintz 2021-04-06 03:51:54 +00:00
parent 6b0dc50689
commit f9d272fee2
5 changed files with 29 additions and 2 deletions

10
bot.py
View file

@ -16,6 +16,7 @@
# along with Emote Manager. If not, see <https://www.gnu.org/licenses/>. # along with Emote Manager. If not, see <https://www.gnu.org/licenses/>.
import base64 import base64
import hashlib
import logging import logging
import traceback import traceback
@ -42,7 +43,7 @@ class Bot(Bot):
with open('data/config.py', encoding='utf-8') as f: with open('data/config.py', encoding='utf-8') as f:
config = eval(f.read(), {}) config = eval(f.read(), {})
super().__init__(config=config, **kwargs) super().__init__(config=config, setup_db=True, **kwargs)
# allow use of the bot's user ID before ready() # allow use of the bot's user ID before ready()
token_part0 = self.config['tokens']['discord'].partition('.')[0].encode() token_part0 = self.config['tokens']['discord'].partition('.')[0].encode()
self.user_id = int(base64.b64decode(token_part0 + b'=' * (3 - len(token_part0) % 3))) self.user_id = int(base64.b64decode(token_part0 + b'=' * (3 - len(token_part0) % 3)))
@ -57,6 +58,13 @@ class Bot(Bot):
utils.SUCCESS_EMOJIS = utils.misc.SUCCESS_EMOJIS = ( utils.SUCCESS_EMOJIS = utils.misc.SUCCESS_EMOJIS = (
self.config.get('response_emojis', {}).get('success', default)) self.config.get('response_emojis', {}).get('success', default))
async def on_command(self, ctx):
user_id_md5 = hashlib.md5(ctx.author.id.to_bytes(8, byteorder='big'), usedforsecurity=False).digest()
await self.pool.execute(
'INSERT INTO invokes (guild_id, user_id_md5, command) VALUES ($1, $2, $3)',
ctx.guild.id, user_id_md5, ctx.command.qualified_name,
)
def main(): def main():
import sys import sys

View file

@ -13,6 +13,11 @@
'discord': 'sek.rit.token', 'discord': 'sek.rit.token',
}, },
# required for metrics
# configure it according to https://magicstack.github.io/asyncpg/current/api/index.html#connection
'database': {
},
'ignore_bots': { 'ignore_bots': {
'default': True, 'default': True,
'overrides': { 'overrides': {

View file

@ -10,5 +10,5 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You may find a copy of the GNU Affero General Public License at https://github.com/EmoteBot/EmoteManager/blob/master/LICENSE.md. You may find a copy of the GNU Affero General Public License at https://github.com/EmoteBot/EmoteManager/blob/metrics/LICENSE.md.
The rest of the source code is also there. The rest of the source code is also there.

View file

@ -4,3 +4,4 @@ bot_bin>=1.5.0,<2.0.0
discord.py>=1.5.0,<2.0.0 discord.py>=1.5.0,<2.0.0
jishaku jishaku
wand wand
asyncpg<1.0.0

13
schema.sql Normal file
View file

@ -0,0 +1,13 @@
SET TIME ZONE 'UTC';
-- inserted for every time a command is invoked
CREATE TABLE invokes (
guild_id BIGINT NOT NULL,
-- hashed for privacy
user_id_md5 BYTEA NOT NULL,
-- the qualified name of the command invoked (https://discordpy.readthedocs.io/en/stable/ext/commands/api.html?highlight=qualified_name#discord.ext.commands.Command.qualified_name)
command TEXT NOT NULL,
invoked_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX invokes_invoked_at_idx ON invokes (invoked_at);