Skip to content

Commit

Permalink
move botlist modules, move tokens, add BotsGG
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayerch1 committed Aug 27, 2021
1 parent 6b27b51 commit 69ed8f7
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 31 deletions.
17 changes: 2 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
# sensitive data
**/botListToken.txt
**/topGGToken.txt
**/topGGToken.txt.bak
**/topGGSecret.txt
**/topGGSecret.txt.bak
**/token.txt
Bot/tokens/**

**/log.txt
**/proposals.txt
**/settings.json
**/servers.json
**/servers_test.json
**/db_username.txt
**/db_password.txt
**/db_host.txt
**/whitelist.txt
testFile.py

calendar_bak.json
servers_bak.json

tmp/
data/db/**
data/db2/**
Expand Down
79 changes: 79 additions & 0 deletions Bot/botLists/BotsGGModule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import discord
from discord.ext import commands, tasks

import requests
import json

from lib.Analytics import Analytics


class TopGG(commands.Cog):

def __init__(self, client):
BotDir = os.getenv('BOT_ROOT_PREFIX')

self.BASE = 'https://discord.bots.gg/api/v1'
self.user_agent = "remindMeBot (https://github.com/Mayerch1/RemindmeBot)"

if os.path.exists(f'{BotDir}tokens/botsGGToken.txt'):
self.client = client
self.token = open(f'{BotDir}tokens/botsGGToken.txt', 'r').readline()[:-1]

print('Started BotsGG job')
self.update_stats.start()

else:
print('Ignoring BotsGG, no Token')


def cog_unload(self):
self.update_stats.cancel()


async def post_count(self, url, payload):
if not self.token:
print('no botsGGToken')
return

url = self.BASE + url

headers = {
'User-Agent' : self.user_agent,
'Content-Type' : 'application/json',
'Authorization': self.token
}

payload = json.dumps(payload)

r = requests.post(url, data=payload, headers=headers)

if r.status_code >= 300:
print(f'BotsGG Server Count Post failed with {r.status_code}')


@tasks.loop(minutes=30)
async def update_stats(self):
"""This function runs every 30 minutes to automatically update your server count."""

server_count = len(self.client.guilds)
Analytics.guild_cnt(server_count)

payload = {
'guildCount': server_count
}
if self.client.shard_count:
payload["shardCount"] = self.client.shard_count
if self.client.shard_id:
payload["shardId"] = self.client.shard_id

await self.post_count( f'/bots/{self.client.user.id}/stats', payload=payload)


@update_stats.before_loop
async def update_stats_before(self):
await self.client.wait_until_ready()


def setup(client):
client.add_cog(TopGG(client))
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
class DiscordBotList(commands.Cog):

def __init__(self, client):
self.BASE = 'https://discordbotlist.com/api/v1'
BotDir = os.getenv('BOT_ROOT_PREFIX')

self.BASE = 'https://discordbotlist.com/api/v1'
self.user_agent = "remindMeBot (https://github.com/Mayerch1/RemindmeBot)"

if os.path.exists('botListToken.txt'):
if os.path.exists(f'{BotDir}tokens/botListToken.txt'):
self.client = client
self.token = open('botListToken.txt', 'r').readline()[:-1]
self.token = open(f'{BotDir}tokens/botListToken.txt', 'r').readline()[:-1]

print('Started botList server')
print('Started DBL job')
self.update_stats.start()

else:
print('Ignoring botList, no Token')
print('Ignoring DBL, no Token')


def cog_unload(self):
Expand All @@ -30,7 +31,7 @@ def cog_unload(self):

async def post_count(self, url, payload):
if not self.token:
print('no DiscordBotList token')
print('no DBL token')
return

url = self.BASE + url
Expand Down
11 changes: 5 additions & 6 deletions Bot/TopGGModule.py → Bot/botLists/TopGGModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
class TopGG(commands.Cog):

def __init__(self, client):
BotDir = os.getenv('BOT_ROOT_PREFIX')

self.BASE = 'https://top.gg/api'

self.user_agent = "remindMeBot (https://github.com/Mayerch1/RemindmeBot)"

if os.path.exists('topGGToken.txt'):
if os.path.exists(f'{BotDir}tokens/topGGToken.txt'):
self.client = client
self.token = open('topGGToken.txt', 'r').readline()[:-1]
self.token = open(f'{BotDir}tokens/topGGToken.txt', 'r').readline()[:-1]

#self.dblpy = dbl.DBLClient(self.client, self.token, autopost=True)
#self.dblpy = dbl.DBLClient(self.bot, self.token)
print('Started topGG server')
print('Started topGG job')
self.update_stats.start()

else:
Expand Down
12 changes: 9 additions & 3 deletions Bot/remindmeBot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
import discord
import asyncio
Expand All @@ -17,7 +18,9 @@
intents.messages = True
intents.guilds = True

token = open('token.txt', 'r').read()
BotDir = os.getenv('BOT_ROOT_PREFIX')

token = open(f'{BotDir}tokens/token.txt', 'r').read()
client = commands.Bot(command_prefix='/', description='Reminding you whenever you want', help_command=None, intents=intents)
slash = SlashCommand(client, sync_commands=True)

Expand Down Expand Up @@ -90,12 +93,15 @@ def main():
Connector.init()
Analytics.init()

client.load_extension(f'TopGGModule')
client.load_extension(f'DiscordBotListModule')
client.load_extension(f'ReminderModule')
client.load_extension(f'ReminderListing')
client.load_extension(f'HelpModule')
client.load_extension(f'TimezoneModule')

client.load_extension(f'botLists.TopGGModule')
client.load_extension(f'botLists.DiscordBotListModule')
client.load_extension(f'botLists.BotsGGModule')

client.run(token)


Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

This bot is inspired by the reddit remindme bot and allows similar usage.

* Create as many Reminders as you want (no rate limit, or vote bounties)
* Create as many Reminders as you want (no rate limit or vote bounties)
* Create intervals (shortest interval is hourly)
* Remind other users and roles (@everyone)
* Create complex repeating patterns (ics-rrules, rfc-5545)
* Set the timezone of your server
* Minimal Permissions required


<img src="https://imgur.com/YE9qXOE.gif" alt="Create Reminder">
Expand Down

0 comments on commit 69ed8f7

Please sign in to comment.