Skip to content

Commit

Permalink
Merge pull request #274 from idoneam/dev
Browse files Browse the repository at this point in the history
Release v1.1.0: Burnside Lobby
  • Loading branch information
davidlougheed authored Mar 21, 2020
2 parents 79fb1c4 + 56d0acf commit 7b0fb07
Show file tree
Hide file tree
Showing 26 changed files with 990 additions and 441 deletions.
4 changes: 4 additions & 0 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Github provides a user-friendly interface for managing issues for a repository.
- **master**: This is the deployment branch, direct push are blocked for both admin and regular members. Ideally, code contained in this branch should be the least error-prone.
- **Feature/Issue branches**: Anytime you want to work on resolving an issue or implementing a new feature, branch off of the `dev` branch into one of these branches. Name the branch `issue-x` where `x` is the issue number with the issue you are trying to resolve/feature you are trying to implement. You can be more descriptive so other people know what exactly you are working on. Example: `issue-42` or `issue-30/paginator` are both acceptable.

### Testing

All new bot functions must be tested. Tests are located in the `tests/` directory, with a filename prefixed with `test_` for each `.py` file in the bot. Tests can be run locally with `poetry run pytest`. If you need help with creating new tests for your new functions, reach out to @jidicula or @davidlougheed.

### Pull requests

When you have finished your task and pushed your work to the corresponding branch on remote, you can create a pull request via Github web interface to integrate your code into production. By default, your PR should be requesting to merge into `dev` -- however, it's good practice to check that this is indeed the case before you submit your PR. After creating a pull request, you should ask at least 1 person to review your work and update it accordingly. If your pull request is approved, changes will be applied to the destination branch, and the feature/enhancement will be deployed eventually.
Expand Down
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ python:

env:
global:
- PIPENV_IGNORE_VIRTUALENVS=1
- PIPENV_VERBOSITY=-1
- POETRY_VIRTUALENVS_IN_PROJECT=true

before_install:
- sed -i "s/KEY/$DISCORD_TOKEN/g" config/config.ini

install:
- pip install pipenv
- pipenv install --dev
- pip install poetry
- poetry install

jobs:
include:
- stage: Build
script: bash ./test.sh
script: pipenv run yapf --diff --recursive .
script: poetry run yapf --diff --recursive .

notifications:
email: false
6 changes: 1 addition & 5 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

# discord-py requirements
import discord
from discord.ext import commands
import asyncio

# for database
import sqlite3

# Other utilities
import os
Expand All @@ -48,6 +43,7 @@
"cogs.reminder",
"cogs.score",
"cogs.subscribers",
"cogs.games",
]

# TODO: SHOULD BE DB
Expand Down
24 changes: 0 additions & 24 deletions Pipfile

This file was deleted.

317 changes: 0 additions & 317 deletions Pipfile.lock

This file was deleted.

23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ your environment of choice and clone into the repository with:
$ git clone https://github.com/idoneam/Canary
```

2. Dependencies are managed with pipenv which can be installed via pip with:
2. Dependencies are managed with poetry which can be installed via pip with:
```bash
$ python3 -m pip install pipenv
$ python3 -m pip install poetry
```

3. Dependencies may be installed using pipenv with the following command:
3. Dependencies may be installed using poetry with the following command:
```bash
$ pipenv install
$ poetry install --no-dev
```

4. Use of the LaTeX equation functionality requires a working LaTeX installation (at the very minimum, `latex` and `dvipng` must be present). The easiest way to do this is to install TeX Live (usually possible through your distro's package manager, or through TeX Live's own facilities for the latest version). See the [TeX Live site](https://tug.org/texlive/) for more information.

5. Development dependencies (YAPF) can be installed alongside all other dependencies with:
5. Development dependencies (YAPF and `pytest`) can be installed alongside all other dependencies with:
```bash
$ pipenv install --dev
$ poetry install
```

6. You may enter the virtual environment generated by the pipenv installation with: `$ pipenv shell` or simply run the bot with `$ pipenv run python3 Main.py`
6. You may enter the virtual environment generated by the pipenv installation with: `$ poetry shell` or simply run the bot with `$ poetry run python3 Main.py`

7. In order to run bots on Discord, you need to [create a bot account](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token).

Expand Down Expand Up @@ -91,18 +91,21 @@ You must set certain values in the `config.ini` file, in particular your Discor
</p>
</details>

## Testing functions
If you installed all dev dependencies, you can run tests with `poetry run pytest`.

## Running the bot
Run `pipenv run python Main.py` in your shell. Ensure that your Discord token is set in the `config.ini` file within the `config` directory.
Run `poetry run python Main.py` in your shell. Ensure that your Discord token is set in the `config.ini` file within the `config` directory.

## Code Linting
We format our code using Google's [YAPF](https://github.com/google/yapf). Our builds will reject code that do not conform to the standards defined in [`.style.yapf`](https://github.com/idoneam/Canary/blob/master/.style.yapf) . You may format your code using :

```
$ pipenv run yapf --recursive --in-place .
$ poetry run yapf --recursive --in-place .
```
and ensure your code conforms to our linting with :
```
$ pipenv run yapf --diff --recursive .
$ poetry run yapf --diff --recursive .
```
## Contributions
Contributions are welcome, feel free to fork our repository and open a pull request or open an issue. Please [review our contribution guidelines](https://github.com/idoneam/Canary/blob/master/.github/contributing.md) before contributing.
5 changes: 1 addition & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
# You should have received a copy of the GNU General Public License
# along with Canary. If not, see <https://www.gnu.org/licenses/>.

import asyncio
import discord
from discord.ext import commands

from config import parser
import logging
import sqlite3
import sys
import traceback

__all__ = ['bot', 'developer_role', 'moderator_role']
Expand Down Expand Up @@ -86,7 +83,7 @@ async def on_command_error(self, ctx, error):
return await ctx.author.send(
'{} can not be used in Private Messages.'.format(
ctx.command))
except:
except Exception:
pass

elif isinstance(error, commands.BadArgument):
Expand Down
3 changes: 1 addition & 2 deletions cogs/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# discord.py requirements
import discord
from discord.ext import commands
import asyncio

# For type hinting
from typing import Dict, List, Optional, Tuple
Expand All @@ -34,7 +33,7 @@
from .utils.paginator import Pages

# For general currency shenanigans
from decimal import *
from decimal import Decimal, InvalidOperation

# For betting
import random
Expand Down
93 changes: 93 additions & 0 deletions cogs/games.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) idoneam (2016-2019)
#
# This file is part of Canary
#
# Canary is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Canary is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Canary. If not, see <https://www.gnu.org/licenses/>.

# discord-py requirements
import discord
from discord.ext import commands

# Other utilities
import re
from .utils.dice_roll import dice_roll
from .utils.clamp_default import clamp_default

ROLL_PATTERN = re.compile(r'^(\d*)d(\d*)([+-]?\d*)$')


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

@commands.command()
async def roll(self, ctx, arg: str = '', mpr: str = ''):
"""
Perform a DnD-style diceroll
[r]d[s][+m] ['each'] Rolls an [s]-sided die [r] times, with modifier
[+-m]. If 'each' is specified, applies modifier
to each roll rather than the sum of all rolls.
All parameters are optional.
Defaults to rolling one 20-sided die.
Examples:
roll rolls a d20
roll d6 rolls one 6-sided die
roll 3d rolls 3 20-sided dice
roll 5d12-4 rolls 5 12-sided dice, subtracting 4 from the total
roll 5d+3 each rolls 5 20-sided dice, adding 3 to each roll
"""
roll_cmd = ROLL_PATTERN.match(arg)
if arg == 'safe': # nice meme bro
await ctx.send('https://media.giphy.com/media/'
'd3mlE7uhX8KFgEmY/giphy.gif')
return
# Applying some bounds on parameters
if roll_cmd is not None:
repeat = clamp_default(roll_cmd.group(1), 1, 10000, 1)
sides = clamp_default(roll_cmd.group(2), 1, 100, 20)
mod = clamp_default(roll_cmd.group(3), -100, 100, 0)
else: # Necessary for empty roll commands - regex won't even match
repeat = 1
sides = 20
mod = 0

if mpr == 'each':
roll_list, total, maximum, minimum = dice_roll(sides,
repeat,
mod,
mpr=True)
mod_desc = ' to each roll'
else:
roll_list, total, maximum, minimum = dice_roll(sides, repeat, mod)
mod_desc = ' to the sum of rolls'
# Now that we have our rolls, prep the embed:
resultsmsg = discord.Embed(description='Rolling {} {}-sided dice'
', with a {} modifier{}'.format(
repeat, sides, mod, mod_desc),
colour=0x822AE0)
if repeat <= 10: # Anything more and the roll list is too long
resultsmsg.add_field(name='Rolls',
value=str(roll_list)[1:-1],
inline=False)
if repeat > 1:
resultsmsg.add_field(name='Sum', value=total)
resultsmsg.add_field(name='Minimum', value=minimum)
resultsmsg.add_field(name='Maximum', value=maximum)
await ctx.send(embed=resultsmsg)


def setup(bot):
bot.add_cog(Games(bot))
27 changes: 19 additions & 8 deletions cogs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

URBAN_DICT_TEMPLATE = "http://api.urbandictionary.com/v0/define?term={}"

LMGTFY_TEMPLATE = "https://lmgtfy.com/?q={}"

try:
os.mkdir('./pickles')
except Exception:
Expand Down Expand Up @@ -106,12 +108,13 @@ def retrieve_string(label):
wind_string = retrieve_string("Wind:")
# Get relative humidity
humidity_string = retrieve_string("Humidity:")
# Get "Feels like" temperature using formula from MetService (Meteorological
# Service of New Zealand), which uses the standard formula for windchill from
# Environment Canada for temperatures of 10°C and less (or the normal
# temperature if the wind speed is less than 5 km/h), the Australian apparent
# temperature for temperatures of 14°C and more (or the normal temperature if
# it is higher), and a linear roll-off of the wind chill between 10°C and 14°C
# Get "Feels like" temperature using formula from MetService
# (Meteorological Service of New Zealand), which uses the standard
# formula for windchill from Environment Canada for temperatures of 10°C
# and less (or the normal temperature if the wind speed is less than 5
# km/h), the Australian apparent temperature for temperatures of 14°C
# and more (or the normal temperature if it is higher), and a linear
# roll-off of the wind chill between 10°C and 14°C
# (https://blog.metservice.com/FeelsLikeTemp)
temperature = float(
re.search(r"-?\d+\.\d", temperature_string).group())
Expand Down Expand Up @@ -376,6 +379,13 @@ async def urban(self, ctx, *, query):

await p.paginate()

@commands.command()
async def lmgtfy(self, ctx, *, query):
"""Generates a Let Me Google that For You link."""
url = LMGTFY_TEMPLATE.format(
query.replace("+", "%2B").replace(" ", "+"))
await ctx.send(url)

@commands.command()
async def tex(self, ctx, *, query: str):
"""Parses and prints LaTeX equations."""
Expand Down Expand Up @@ -504,7 +514,8 @@ async def modpow(self, ctx, a, b, m):
async def food_spot(self, ctx, *args):
"""Posts a food sale in #foodspotting.
Use: `?foodspot Samosas in leacock`
You can also attach one picture to your message (Write the command in the uploaded image caption)"""
You can also attach one picture to your message (Write the command in
the uploaded image caption)"""
if utils.get(ctx.author.roles,
name=self.bot.config.no_food_spotting_role):
return
Expand Down Expand Up @@ -533,7 +544,7 @@ async def food_spot(self, ctx, *args):
@commands.command()
async def choose(self, ctx, *, inputOpts: str):
"""Randomly chooses one of the given options delimited by semicola.
Usage: ?choose opt1;opt2
Usage: ?choose opt1;opt2
"""
opts = inputOpts.split(';')
sel = random.randint(0, (len(opts) - 1))
Expand Down
10 changes: 4 additions & 6 deletions cogs/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@
# imports for Discord
import discord
from discord.ext import commands
import asyncio

# misc imports
import os
import sys
import random
import numpy as np
import cv2
import math
from functools import wraps
from io import BytesIO
import traceback


def filter_image(func):
Expand Down Expand Up @@ -180,12 +176,14 @@ async def cblur(self, _ctx, radius='10', image=None):
v_pad = int(r - height / 2)
h_pad = int(r - width / 2)

# pad border to avoid black regions when transforming image back to normal
# pad border to avoid black regions when transforming image back to
# normal
image = cv2.copyMakeBorder(image, v_pad, v_pad, h_pad, h_pad,
cv2.BORDER_REPLICATE)
image = self._polar(image)

# wrap border to avoid the sharp horizontal line when transforming image back to normal
# wrap border to avoid the sharp horizontal line when transforming
# image back to normal
image = cv2.copyMakeBorder(image, half_radius, half_radius,
half_radius, half_radius, cv2.BORDER_WRAP)
image = cv2.blur(image, (1, radius))
Expand Down
Loading

0 comments on commit 7b0fb07

Please sign in to comment.