Skip to content
Permalink
Browse files
Added comments and other small adjustments
  • Loading branch information
stavilam committed Nov 28, 2018
1 parent f5f92a4 commit e315042b4f6cc5f02712b24685000274dd4cc56e
Showing 1 changed file with 46 additions and 29 deletions.
@@ -1,64 +1,76 @@
import asyncio
import discord
from discord.ext import commands
from botClient import colorCode
import random
import time
import datetime
from botClient import client

"""Module used for many basic functions such as user and server information, counting message cache, mini-games like
number and dice rolls etc."""


class BasicFunctions:
def __init__(self, client):
self.client = client

@commands.command(aliases = ['msgcount','mcount','mcache'])
@commands.command(aliases = ['msgcount', 'mcount', 'mcache'])
async def cache_message_count(self, ctx):
"""Counts your recent messages"""
try:
await ctx.message.delete()
except discord.HTTPException:
pass
counter = 0
tmp = await ctx.message.channel.send('Calcuating messages...')
async for log in ctx.message.channel.history(limit = int(1000)):
tmp = await ctx.send('Calcuating messages...')
async for log in ctx.message.channel.history(limit=int(1000)):
if log.author == ctx.message.author:
counter += 1
await tmp.edit(content=f'You have {counter} messages.')
await tmp.edit(content=f'You have {counter} messages.', delete_after=5)

@commands.command(aliases = ['hey', 'greetings', 'howdy', 'heya'])
"""Mostly used to test whether the bot is responsive or not"""
@commands.command(aliases=['hey', 'greetings', 'howdy', 'heya'])
async def hello(self, ctx):
await ctx.message.channel.send(f'Hello, {ctx.message.author.mention}!')

@commands.command(aliases = ['youok'])
async def uok(self, ctx):
await ctx.message.channel.send('Yes I am.')

@commands.command(aliases = ['coin','coinflip'])
async def flip(self, ctx):
tup = ['Heads','Tails']
await ctx.message.channel.send(random.choice(tup))
@commands.command(name='flip', aliases=['coin', 'coinflip'])
async def flip_coin(self, ctx):
"""Flips a coin"""
coinSide = ['Heads', 'Tails']
await ctx.send(random.choice(coinSide))

@commands.command(aliases = ['diceroll','rolldice']) #generate rand int between 1 and 6 diceNumber times (default 1)
async def dice(self, ctx, diceNumber = 1):
@commands.command(name='dice', aliases=['diceroll', 'rolldice'])
@commands.cooldown(3, 10, commands.BucketType.user)
async def roll_dice(self, ctx, diceNumber = 1):
"""Rolls a dice (max 5 dices)"""
if diceNumber > 5:
await ctx.message.channel.send('Too many dices. Max dices: 5')
elif diceNumber == 1:
await ctx.message.channel.send(f"{ctx.message.author}'s dice shows a " + str(random.randint(1, 6)) + ".")
else:
embed = discord.Embed(title = f"{ctx.message.author}'s dice results", color = colorCode[0])
embed = discord.Embed(title=f"{ctx.message.author}'s dice results", color=colorCode[0])
embed.set_thumbnail(url=ctx.message.author.avatar_url)
diceValTotal = 0
for i in range(1, diceNumber + 1):
diceVal = random.randint(1,6)
diceVal = random.randint(1, 6)
diceValTotal += diceVal
embed.add_field(name=f'Dice {i} rolled ' + str(diceVal), value='-----------------', inline=False)
embed.add_field(name=f'Total is {diceValTotal}', value='End of dice results.', inline=False)
await ctx.message.channel.send(embed=embed)

@commands.command(aliases = ['rollnumber','randomn']) #generate a random int between 1 and maxRoll(default 100)
async def roll(self, ctx, maxRoll = 100):
@commands.command(name='roll', aliases=['rollnumber', 'randomn'])
async def roll_number(self, ctx, maxRoll = 100):
"""Rolls a random number from 1 to max 100k. (default 100)"""
if maxRoll > 100000:
await ctx.send("Can't roll more than 100000 (100k).")
return
await ctx.message.channel.send(f'{ctx.message.author} rolled ' + str(random.randint(1,maxRoll)) + '.')

@commands.command(aliases = ['info', 'uinfo', 'infouser', 'user'])
async def userinfo(self, ctx, member : discord.Member = None):
@commands.command(name='user', aliases=['info', 'uinfo', 'infouser'])
@commands.cooldown(3, 10, commands.BucketType.user)
async def user_info(self, ctx, member : discord.Member = None):
"""Shows info about the mentioned user's account."""
try:
await ctx.message.delete()
except discord.HTTPException:
pass
if member is None:
member = ctx.message.author
if ctx.message.guild == None:
@@ -90,14 +102,20 @@ class BasicFunctions:
inline=False)
embed.add_field(name='Join date', value=f'{member.joined_at.strftime(timeFormat)}', inline=False)
embed.set_footer(text=f'Info requested by {ctx.message.author} on {ctx.message.created_at.strftime(timeFormat)}'
,icon_url= ctx.message.author.avatar_url)
, icon_url=ctx.message.author.avatar_url)
await ctx.message.channel.send(embed=embed)

@commands.command(aliases = ['server','infoserver','srvinfo'])
async def serverinfo(self, ctx):
@commands.command(name='server', aliases=['infoserver', 'srvinfo'])
@commands.cooldown(3, 10, commands.BucketType.user)
async def server_info(self, ctx):
"""Shows info about the channel's server."""
if ctx.message.guild == None:
await ctx.send('This command is only available in server/guild channels.')
return
try:
await ctx.message.delete()
except discord.HTTPException:
pass
timeFormat = "%A, %d %B %Y @ %X"
embed = discord.Embed(title='Server Info', color=colorCode[0])
embed.set_thumbnail(url=ctx.guild.icon_url)
@@ -117,6 +135,5 @@ class BasicFunctions:
await ctx.send(embed=embed)



def setup(client):
client.add_cog(BasicFunctions(client))

0 comments on commit e315042

Please sign in to comment.