Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
itchono committed Jun 15, 2020
1 parent 26351a0 commit 37d5fc1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
47 changes: 46 additions & 1 deletion keep_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
import logging
import os

import discord
from discord.ext import commands, tasks

import requests
import json
import aiohttp
import urllib.request

logging.getLogger('werkzeug').disabled = True
os.environ['WERKZEUG_RUN_MAIN'] = 'true'

Expand All @@ -15,7 +23,7 @@

@app.route('/')
def main():
return 'Comrade BOT is online - Uptime: {}'.format(datetime.utcnow() -
return 'SET Hacks Bot is online - Uptime: {}'.format(datetime.utcnow() -
t_start)


Expand All @@ -33,3 +41,40 @@ def keep_alive():
def shutdown():
server = Thread(target=run)
server._stop()

# for repl.it
class SelfPing(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.lastping = None
self.response = None
self._last_member = None

self.selfping.start()

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

@tasks.loop(minutes=1.0)
async def selfping(self):
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
headers={'User-Agent':user_agent}
url = 'https://SET-Bot--itchono.repl.co'

try:
request = urllib.request.Request(url,None,headers)

response = urllib.request.urlopen(request)
self.response = response.read().decode("utf-8")
except:
print("ERROR pinging self!")

@commands.command(name="ping")
async def ping(self, ctx : commands.Context):
await ctx.send("Last Response:`{}`".format(self.response))


@selfping.before_loop
async def before_selfping(self):
await self.bot.wait_until_ready()
print("Self ping routine started.")
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
By Mingde Yin (Itchono)
v1.0 June 7, 2020
v1.1 June 4, 2020
Changelog:
1.1 - Higher Uptime
1.0 - Initial Release
'''

Expand All @@ -22,6 +23,8 @@

client = commands.Bot(command_prefix="$")

client.add_cog(SelfPing(client))

@client.command()
async def info(ctx : commands.Context):
await ctx.send("I am SET BOT")
Expand All @@ -45,6 +48,8 @@ async def on_message(message : discord.Message):
await m.edit(roles=roles)
await message.channel.send("Thanks {}, your role has been added!".format(message.author.mention))

await client.process_commands(message)

@client.event
async def on_ready():
await client.change_presence(status=discord.Status.online,
Expand Down

0 comments on commit 37d5fc1

Please sign in to comment.