-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ufosc/develop
Merge develop into master Changes: - Added a database backend - Added error message handling - Added a welcome message for new members - Add a lot of helloworld texts
- Loading branch information
Showing
41 changed files
with
663 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
|
||
[*.py] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
__pycache__/ | ||
*.jpg | ||
config.py | ||
database/data/sqlite3.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
# Misc | ||
ERROR_REPORT_URL = 'https://github.com/ufosc/albot-and-albot' | ||
BOT_NAME = 'ALBot' | ||
|
||
# Embed colors | ||
EMBED_COLOR_STANDARD = 0x00529b | ||
EMBED_COLOR_ERROR = 0x913232 | ||
|
||
# Message reaction types | ||
# 'CONFLICT' means that this reaction type MUST be unique, or at least | ||
# not be the same as another CONFLICT-type reaction, as the program | ||
# could potentially use this reaction as a user-input button. | ||
REACTION_DELETE = '\U0001f6ae' # CONFLICT | ||
REACTION_NEW = '\u2733' # CONFLICT | ||
REACTION_EXPAND = '\U0001f521' # CONFLICT | ||
REACTION_DENY = '\u26d4' # | ||
REACTION_ERROR = '\u26a0' # | ||
REACTION_NOT_FOUND = '\u2139' # Same as REACTION_INFO | ||
REACTION_INFO = '\u2139' # Same as REACTION_NOT_FOUND |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import sys | ||
import traceback | ||
import math | ||
|
||
import discord | ||
from discord.ext import commands | ||
|
||
import cogs.CONSTANTS as CONSTANTS | ||
from database.database import SQLCursor, SQLConnection | ||
from cogs.messages import track | ||
|
||
class ALBotErrorHandlers: | ||
""" Handles errors """ | ||
|
||
def __init__(self, bot, db): | ||
self.bot = bot | ||
self.db = db | ||
|
||
def _construct_error_embed(self, command_name, error_name, error_text, full_command_string, full_backtrace=None): | ||
title = "{err} An error was encountered while processing the {0} command".format(command_name, err=CONSTANTS.REACTION_ERROR) | ||
embed = discord.Embed(title=title, colour=discord.Colour(CONSTANTS.EMBED_COLOR_ERROR), description="**{0}**: ```{1}```".format(error_name, str(error_text))) | ||
embed.set_footer(text="Report bugs at {url}".format(url=CONSTANTS.ERROR_REPORT_URL)) | ||
embed.add_field(name="While processing the command:", value="``{0}``".format(full_command_string), inline=False) | ||
if full_backtrace: | ||
itr = 1 | ||
total_itrs = math.ceil(len(full_backtrace)/512) | ||
while len(full_backtrace) > 0: | ||
if len(full_backtrace) > 512: | ||
embed.add_field(name="Backtrace ({0} of {1}):".format(itr, total_itrs), value="```{0}```".format(full_backtrace[:512]), inline=False) | ||
full_backtrace = full_backtrace[512:] | ||
itr = itr + 1 | ||
else: | ||
embed.add_field(name="Backtrace ({0} of {1}):".format(itr, total_itrs), value="```{0}```".format(full_backtrace), inline=False) | ||
break | ||
else: | ||
embed.add_field(name='Press {expand}'.format(expand=CONSTANTS.REACTION_EXPAND), value='for full error backtrace', inline=False) | ||
|
||
return embed | ||
|
||
def _construct_unknown_command_embed(self, error_text, full_text): | ||
title = "{notfound} Invalid command.".format(notfound=CONSTANTS.REACTION_NOT_FOUND) | ||
embed = discord.Embed(title=title, colour=discord.Colour(CONSTANTS.EMBED_COLOR_ERROR), description='```{0}```'.format(error_text)) | ||
embed.set_footer(text="Use {0}help for a list of commands.".format(self.bot.command_prefix)) | ||
embed.add_field(name="While processing the command:", value="``{0}``".format(full_text), inline=False) | ||
|
||
return embed | ||
|
||
async def on_command_error(self, ctx, error): | ||
if type(error) == discord.ext.commands.MissingPermissions: | ||
await ctx.message.add_reaction(CONSTANTS.REACTION_DENY) | ||
embed = discord.Embed(title='{deny} Insufficient Permissions'.format(deny=CONSTANTS.REACTION_DENY), colour=discord.Colour(CONSTANTS.EMBED_COLOR_ERROR), description="You are not permitted to run the command ``{0}``".format(ctx.message.content)) | ||
embed.add_field(name="Reason:", value=str(error)) | ||
msg = await ctx.send(content='', embed=embed) | ||
await track(msg, ctx.author) | ||
else: | ||
embed = None | ||
if not ctx.command: | ||
embed = self._construct_unknown_command_embed(str(error), ctx.message.content) | ||
else: | ||
embed = self._construct_error_embed(ctx.command.name, str(type(error)), str(error), ctx.message.content) | ||
|
||
await ctx.message.add_reaction(CONSTANTS.REACTION_ERROR) | ||
msg = await ctx.send(content='', embed=embed) | ||
await track(msg, ctx.author) | ||
if not ctx.command: | ||
return | ||
await msg.add_reaction(CONSTANTS.REACTION_EXPAND) | ||
with SQLCursor(self.db) as cur: | ||
bt_string = ''.join(traceback.format_exception(type(error), error, error.__traceback__)) | ||
print('{bname} encountered an error:\n{0}'.format(bt_string, bname=CONSTANTS.BOT_NAME)) | ||
cur.execute('INSERT INTO error_messages (message_id, channel_id, command_name, error_name, error_text, full_backtrace, full_command_string) VALUES (?,?,?,?,?,?,?);',(msg.id, msg.channel.id, ctx.command.name, str(type(error)), str(error), bt_string, ctx.message.content)) | ||
|
||
async def on_raw_reaction_add(self, payload): | ||
if payload.user_id == self.bot.user.id: | ||
return | ||
elif payload.emoji.name == CONSTANTS.REACTION_EXPAND: | ||
row = None | ||
with SQLCursor(self.db) as cur: | ||
cur.execute('SELECT command_name, error_name, error_text, full_command_string, full_backtrace FROM error_messages WHERE message_id=? AND channel_id=?;',(payload.message_id, payload.channel_id)) | ||
row = cur.fetchone() | ||
if not row: | ||
return | ||
|
||
to_edit = await self.bot.get_channel(payload.channel_id).get_message(payload.message_id) | ||
new_embed = self._construct_error_embed(row[0],row[1],row[2],row[3],row[4]) | ||
await to_edit.edit(content='{err} Command error {err}'.format(err=CONSTANTS.REACTION_ERROR),embed=new_embed) | ||
|
||
async def on_raw_reaction_remove(self, payload): | ||
if payload.user_id == self.bot.user.id: | ||
return | ||
if payload.emoji.name == CONSTANTS.REACTION_EXPAND: | ||
row = None | ||
with SQLCursor(self.db) as cur: | ||
cur.execute('SELECT command_name, error_name, error_text, full_command_string, full_backtrace FROM error_messages WHERE message_id=? AND channel_id=?;',(payload.message_id, payload.channel_id)) | ||
row = cur.fetchone() | ||
if not row: | ||
return | ||
|
||
to_edit = await self.bot.get_channel(payload.channel_id).get_message(payload.message_id) | ||
new_embed = self._construct_error_embed(row[0],row[1],row[2],row[3]) | ||
await to_edit.edit(content='{err} Command error {err}'.format(err=CONSTANTS.REACTION_ERROR),embed=new_embed) | ||
|
||
|
||
|
||
def setup(bot): | ||
bot.add_cog(ALBotErrorHandlers(bot, SQLConnection())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```bash | ||
echo 'Hello, World!' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```c | ||
#include <stdio.h> | ||
int main(void) { | ||
puts("Hello, World!"); | ||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
```cobol | ||
IDENTIFICATION DIVISION. | ||
PROGRAM-ID. HELLO-WORLD. | ||
* simple hello world program | ||
PROCEDURE DIVISION. | ||
DISPLAY 'Hello world!'. | ||
STOP RUN. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```cpp | ||
#include <iostream> | ||
int main() { | ||
std::cout << "Hello, World!" << std::endl; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```csharp | ||
using System; | ||
public class Program { | ||
public static void Main(string[] args) { | ||
Console.WriteLine("Hello, World!"); | ||
} | ||
}``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```erlang | ||
-module(hello). | ||
-export([hello_world/0]). | ||
|
||
hello_world() -> io:fwrite("hello, world\n"). | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```go | ||
package main | ||
import "fmt" | ||
func main() { | ||
fmt.Println("hello world") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```haskell | ||
putStrLn "Hello, World!" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ public class Main { | |
System.out.prinlnt("Hello, World!"); | ||
} | ||
} | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```js | ||
console.log("Hello World"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```julia | ||
println("hello world") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
```lisp | ||
; LISP | ||
(DEFUN HELLO-WORLD () | ||
(PRINT (LIST 'HELLO 'WORLD))) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```lua | ||
print("Hello World") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```objectivec | ||
#import <Foundation/Foundation.h> | ||
|
||
int main(int argc, const char * argv[]) { | ||
@autoreleasepool { | ||
// insert code here... | ||
NSLog(@"Hello, World!"); | ||
} | ||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```pascal | ||
program Hello; | ||
begin | ||
writeln ('Hello, world.'); | ||
end. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```perl | ||
print "Hello, World!\n"; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```php | ||
echo('Hello, World!'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
```python | ||
print("Hello, World!") | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```ruby | ||
puts "Hello, World!" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
fn main() { | ||
println!("Hello, World!"); | ||
} | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```scala | ||
object HelloWorld { | ||
def main(args: Array[String]): Unit = { | ||
println("Hello, world!") | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```swift | ||
print("Hello, World!") | ||
``` |
Oops, something went wrong.