Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import discord
from discord.ext import commands
from botClient import colorCode
import random
"""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'])
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.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.', delete_after=5)
"""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(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(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.set_thumbnail(url=ctx.message.author.avatar_url)
diceValTotal = 0
for i in range(1, diceNumber + 1):
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(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(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:
embed = discord.Embed(title=f'{member}', description=
'For full user details, please use this command in a server/guild channel.', color=colorCode[0])
embed.set_thumbnail(url=member.avatar_url)
embed.add_field(name='User ID', value=f'{member.id}', inline=True)
embed.add_field(name='Display Name', value=f'{member.display_name}', inline=True)
embed.add_field(name='Account created', value=str(member.created_at.strftime("%A, %d %B %Y @ %X")),
inline=False)
await ctx.send(embed=embed)
return
timeFormat = "%A, %d %B %Y @ %X"
embed = discord.Embed(title = f'{member}', color = colorCode[0])
embed.set_thumbnail(url=member.avatar_url)
embed.add_field(name='User ID', value=f'{member.id}', inline=True)
embed.add_field(name='Nick', value=f'{member.nick}',inline=True)
embed.add_field(name='Status', value=f'{member.status}', inline=True)
embed.add_field(name='Top Role', value=str(member.top_role), inline=True)
if member.voice == None:
embed.add_field(name='Voice Activity', value='Not connected', inline=True)
else:
embed.add_field(name='Voice Activity', value=f'{member.voice.channel}', inline=True)
if member.activity == None:
embed.add_field(name='Currently playing', value='Nothing', inline=True)
else:
embed.add_field(name='Currently playing', value=str(member.activity.name), inline=True)
embed.add_field(name='Account created', value=str(member.created_at.strftime(timeFormat)),
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)
await ctx.message.channel.send(embed=embed)
@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)
embed.add_field(name='Name', value=ctx.guild.name, inline=True)
embed.add_field(name='Owner', value=ctx.guild.owner, inline=True)
embed.add_field(name='Members', value=ctx.guild.member_count, inline=True)
counter = 0
for user in ctx.guild.members:
if user.status != discord.Status.offline:
counter += 1
embed.add_field(name='Currently Online', value=counter, inline=True)
embed.add_field(name='Region', value=ctx.guild.region, inline=True)
embed.add_field(name='Verification Level', value=ctx.guild.verification_level, inline=True)
embed.add_field(name='Created at', value=ctx.guild.created_at.strftime(timeFormat), inline=True)
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)
await ctx.send(embed=embed)
def setup(client):
client.add_cog(BasicFunctions(client))