Skip to content

Commit

Permalink
new Ascii module and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Nov 14, 2020
1 parent cbc52c9 commit d944717
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 19 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,29 @@ The bot is written in **Python 3.8**, you can run it via `python bot.py` from co

## Configuration

1. `config.json` is where all of the bot configuration will be placed. The only fields that are essential for running the bot are `Token` and `Prefix`
1. `config.json` is where all of the bot configuration will be placed. The only fields that are essential for running the bot are `Token` and `Prefix`.

```JSON
```json
{
"Token": "Get this from the developer dashboard!",
"Prefix": "[]"
"Token": "get it from discord developer portal",
"Prefix": "[]",
"mails_channel": "mails",
"server_name": "server's name here"
}
```

2. Add details to `cogs/modmail.py`
2. give the bot `Administrator` permissions.

```Python
mails_channel = "mails" # channel to receive modmails
server_name = "server name" #input server's name here
```
3. Run `setup` command in the discord server.(for running this command, the user will need administrator permissions)

3. Run `setup` command in the discord server.
## What is new?
<p>
<img alt="Release" src=https://img.shields.io/github/v/release/billydevyt/RoboBilly?style=flat-square>
</p>

- New Ascii text art generator module with with many fonts.
- Error handling module
- All configuration of the bot are moved to `config.json`

## Features

Expand All @@ -59,6 +64,7 @@ server_name = "server name" #input server's name here
|Moderation Module|All Moderation tools needed to keep the server safe and peaceful.|
|User Module|A lot of Fun & useful commands.|
|custom commands|custom command module, add custom commands|
|Error Handling|error handling module|

## Contributing

Expand Down
2 changes: 2 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
client.load_extension('cogs.user')
client.load_extension('cogs.Bot')
client.load_extension('cogs.modmail')
client.load_extension('cogs.rules')
client.load_extension('cogs.error_handling')

#===================================== EVENTS =======================================#

Expand Down
25 changes: 25 additions & 0 deletions cogs/error_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import discord
from discord.ext import commands


class ErrorHandling(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.Cog.listener()
async def on_command_error(self, ctx, error):
"""Command error handler"""
embed = discord.Embed(color=discord.Color.red())
if isinstance(error, commands.CommandNotFound):
embed.title = "Command not Found"
embed.description = "Recheck what you've typed."
await ctx.send(embed=embed)

elif isinstance(error, commands.CommandOnCooldown):
embed.title = "Whoa chill with it"
embed.description = "Command is on cooldown."
await ctx.send(embed=embed)


def setup(bot):
bot.add_cog(ErrorHandling(bot))
40 changes: 40 additions & 0 deletions cogs/fonts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"fonts1":[
"alligator",
"alligator2",
"banner",
"banner3-D",
"basic",
"bell",
"binary",
"block",
"bubble"
],
"fonts2":[
"catwalk",
"dotmatrix",
"hex",
"lcd",
"linux",
"marquee",
"os2",
"pepper",
"poison"
],
"fonts3":[
"sblood",
"script",
"shadow",
"short",
"speed",
"starwars",
"thick",
"thin",
"tiles"
],
"fonts4":[
"tombstone",
"weird",
"wavy"
]
}
1 change: 1 addition & 0 deletions cogs/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async def user(self, ctx, page: int = 1):
embed.add_field(name='google', value='description', inline=False)
embed.add_field(name='bing', value='description', inline=False)
embed.add_field(name='dontasktoask', value="don't ask to ask, Just ask!", inline=False)
embed.add_field(name='ascii', value='Ascii art', inline=False)

# details
embed.set_footer(text=f'page {page}/{total_pages}')
Expand Down
22 changes: 16 additions & 6 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@
from discord.ext.commands import has_permissions, MissingPermissions, BadArgument
import json

with open('./config.json', 'r') as f:
try:
data = json.load(f)
_mails_channel = data["mails_channel"]
_server_name = data["server_name"]
except:
print("config.json is not configured correctly")

class DataClass(object):
mails_channel = _mails_channel
server_name = _server_name


class modmail(commands.Cog):
def __init__(self, bot):
self.bot = bot
data = DataClass()
self.mails_channel = data.mails_channel
self.server_name = data.server_name

#=========================== DETAILS ==============================#

mails_channel = "mails" # channel to receive modmails
server_name = "server's name" #input server's name here

#==================================================================#
@commands.command()
@commands.guild_only()
@has_permissions(administrator=True)
Expand Down
141 changes: 141 additions & 0 deletions cogs/rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import discord
from discord.ext import commands
from discord.ext.commands.cooldowns import BucketType


class crules(object):
rules = [
"Follow the Discord Terms of Service and the Community Guidelines",
"Don't be an asshole",
"No discord invite links",
"NSFW content is not allowed to any degree",
"Keep it english in every chat",
"No Political, religious, racial or highly depressive discussions",
"Keep content in their respective channels",
"No Promotion outside of #🔰│promotion",
"Do not share personal information about others without their consent",
"Staff will always have the last word",
"Do not minimod",
"Keep chat clean"
]

ruleinfo = [
"You can find the TOS here and the Community Guidelines at https://discord.com/terms.",
"This includes things spamming, spoiling and being disrespectful.",
"This includes sending invite links to server members without it being previously discussed.",
"This also means any memes that are NSFW are not allowed.",
"You are only allowed to speak a different language in #🤠│spam-east.",
"If you feel like anyone is overstepping this rule, ping a staff member.",
"Read channel descriptions and names.",
"This includes telling people to check out #🔰│promotion.",
"Respect each others privacy.",
"If you feel like you’ve been treated unfairly, contact a staff member of higher power.",
"This means if someone is breaking the rules, do not personally tell them not to, instead DM or ping staff about it and let the staff handle it.",
"This mean no full caps, no copypastas or tYpInG LiKE tHIs."
]


class rules(commands.Cog):
def __init__(self, bot):
self.bot = bot

# variables
right = '✅'
wrong = '❌'

def hembed(self, st: bool):
if st:
embed = discord.Embed(
color=discord.Color.blue()
)
else:
embed = discord.Embed(
color=discord.Color.red()
)
return embed

@commands.command(name="rule")
@commands.guild_only()
@commands.has_permissions(manage_messages=True)
@commands.cooldown(rate=1, per=3, type=BucketType.default)
async def _rule(self, ctx, n: int=None):
'''Displays the nth rule, if exits'''
await ctx.message.delete()

ctx.trigger_typing()
if n is not None:
try:
# deciding values
rulenumber = 'Rule {0}'.format(n)
rule = crules.rules[n - 1]
ruleinfo = crules.ruleinfo[n - 1]

# sending information
embed = self.hembed(True)
embed.set_author(name=rulenumber)

# fields
embed.add_field(name=rule, value=ruleinfo, inline=False)

# indication
emoji = self.right
except:
embed = self.hembed(False)

# fields
embed.add_field(name="syntax error", value="Rule doesn't exist", inline=False)

# indication
emoji = self.wrong
else:
# sending information
embed = self.hembed(False)
embed.set_author(name="Server Rules Command")

# fields
embed.add_field(name="How to use it?", value="Add the Number of rule you want to see/show as an argument \n > []rule [number]", inline=False)

# indication
emoji = self.right
sent = await ctx.send(embed=embed)

# indication
await sent.add_reaction(emoji)

@commands.command(name="rules")
@commands.has_permissions(manage_messages=True)
@commands.cooldown(rate=1, per=3, type=BucketType.default)
async def _rules(self, ctx):
'''Displays all rules in one command'''
await ctx.message.delete()

ctx.trigger_typing()
embed = self.hembed(True)
embed.set_author(name='Server Rules!')
if len(crules.rules) != 0:
# indication
emoji = self.right

# fields
for i in range(len(crules.rules)):
# deciding values in each loop
rulenumber = 'Rule {0}'.format(i+1)
description = ("**{0}**\n{1}".format(crules.rules[i], crules.ruleinfo[i]))

# adding field
embed.add_field(name=rulenumber, value=description, inline=False)
else:
# indication
emoji = self.wrong

# fields
embed.add_field(name="No Server Rules", value="This server currently has no rules set", inline=False)
embed.set_footer(text='use []rule [number] to view each rules*')

# indication
sent = await ctx.send(embed=embed)
await sent.add_reaction(emoji)

# =========================================================================================== #
def setup(bot):
bot.add_cog(rules(bot))
69 changes: 67 additions & 2 deletions cogs/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from discord.ext.commands import has_permissions, MissingPermissions, BadArgument
import requests, json
from datetime import timedelta, datetime

import pyfiglet
class user(commands.Cog):
api_key = "bbde6a19c33fb4c3962e36b8187abbf8"
base_url = "http://api.openweathermap.org/data/2.5/weather?"
Expand Down Expand Up @@ -166,7 +166,72 @@ async def codeblocktriggers(self, ctx, *, args='nothing'):
thing = discord.Embed(title="How to use Code Blocks Triggers", description="> when making codeblocks, add your language name on the beginning.\njust like this - ````python` for python language", color= discord.Color.blue())
await (ctx.channel).send(embed=thing)
print(f"Event. {ctx.author.name} used how to use code blocks, bruh")

@commands.group(name="ascii", aliases=["Ascii", "art", "asc"])
async def ascii(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.trigger_typing()
embed = discord.Embed(title="Ascii Modules", description="use []ascii <module>", color = discord.Color.blue())
embed.add_field(name="Word", value="Shows ascii art of given text.", inline=False)
embed.add_field(name="Fonts", value="See available Fonts.", inline=False)
embed.set_footer(text="use []ascii <module> <args>")
await ctx.send(embed=embed)


@ascii.command(name="word", aliases=["w", "Word", "W"])
async def word(self, ctx, word:str = "hey", font:str = "standard"):
try:
result = pyfiglet.figlet_format(word, font = font)
except:
result = f"There is no font called {font}."
await ctx.send("```\n" + result + "\n```")

@ascii.command(name="fonts", aliases=["font", "f"])
async def fonts(self, ctx, page:int=1):
total_pages = 4
with open('./cogs/fonts.json', 'r') as f:
try:
data = json.load(f)

if page == 1:
page_data = data['fonts1']
page_no = 1
elif page == 2:
page_data = data['fonts2']
page_no = 2
elif page == 3:
page_data = data['fonts3']
page_no = 3
elif page == 4:
page_data = data['fonts4']
page_no = 4
elif page is None:
page_data = data['fonts1']
page_no = 1
else:
page_data = "more fonts will be added in future"
page_no = 0
except:
print("fonts.json loading error")

if page_data is not None:
Separator = "\n"
fields = Separator.join(page_data)

#embeding
embed = discord.Embed(color = discord.Color.blue())
embed.set_author(name='Ascii Art')
embed.add_field(name='Fonts page', value=fields, inline=False)
if page_no != 0:
embed.set_footer(text=f"page: {page_no}/{total_pages}")
else:
embed.set_footer(text="use []ascii fonts <page_no>")
await ctx.send(embed=embed)
else:
print("looks like there's a problem with page_data")


#===================================== ADD COG ======================================#

def setup(bot):
bot.add_cog(user(bot))
bot.add_cog(user(bot))
Loading

0 comments on commit d944717

Please sign in to comment.