Add CI checks
This commit is contained in:
parent
df2b5eb814
commit
ae3cec1082
22
.drone.yml
22
.drone.yml
|
@ -4,8 +4,26 @@ type: docker
|
|||
name: default
|
||||
|
||||
steps:
|
||||
- name: lint
|
||||
- name: flake8
|
||||
image: python:3-alpine
|
||||
depends_on:
|
||||
- clone
|
||||
commands:
|
||||
- pip install -r requirements-dev.txt
|
||||
- flake8 .
|
||||
- flake8 breadbot
|
||||
|
||||
- name: isort
|
||||
image: python:3-alpine
|
||||
depends_on:
|
||||
- clone
|
||||
commands:
|
||||
- pip install -r requirements-dev.txt
|
||||
- isort --check --diff breadbot
|
||||
|
||||
- name: mypy
|
||||
image: python:3-alpine
|
||||
depends_on:
|
||||
- clone
|
||||
commands:
|
||||
- pip install -r requirements-dev.txt
|
||||
- mypy breadbot
|
||||
|
|
|
@ -4,6 +4,9 @@ breadbot
|
|||
A Python IRC bot built using the `pinhook`_ framework to encourage
|
||||
addiction to bread on breadpunk's own irc server.
|
||||
|
||||
.. image:: https://drone.tildegit.org/api/badges/breadpunk/breadbot/status.svg
|
||||
:target: https://drone.tildegit.org/breadpunk/breadbot
|
||||
|
||||
Data files
|
||||
----------
|
||||
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import re
|
||||
|
||||
import yaml
|
||||
from irc.client import NickMask
|
||||
from pinhook import plugin, bot
|
||||
from irc.client import Event, NickMask, ServerConnection # type: ignore
|
||||
from pinhook import bot, plugin # type: ignore
|
||||
|
||||
RELAY_REGEX = re.compile(r'^<([^@]+@(?:tilde|bread))>\s?(.*)$')
|
||||
|
||||
|
||||
class BreadBot(bot.Bot):
|
||||
|
||||
def on_welcome(self, c, e):
|
||||
def on_welcome(self, c: ServerConnection, e: Event) -> None:
|
||||
c.mode(self.bot_nick, '+B')
|
||||
super().on_welcome(c, e)
|
||||
for channel in self.chanlist:
|
||||
self.process_output(c, channel, plugin.message('bread'))
|
||||
|
||||
def process_event(self, c, e):
|
||||
def process_event(self, c: ServerConnection, e: Event) -> None:
|
||||
# Handle BreadRelay by suppressing it
|
||||
if e.source.nick == 'BreadRelay' and e.arguments:
|
||||
match = RELAY_REGEX.match(e.arguments[0])
|
||||
|
@ -30,12 +31,10 @@ class BreadBot(bot.Bot):
|
|||
if e.source.nick == self.bot_nick:
|
||||
return
|
||||
|
||||
print(e.source, e.arguments)
|
||||
|
||||
return super().process_event(c, e)
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Breadpunk Bread Bot',
|
||||
)
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
from pinhook import plugin
|
||||
from pathlib import Path
|
||||
import logging
|
||||
import re
|
||||
import random
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from pinhook import plugin # type: ignore
|
||||
from pinhook.bot import Bot # type: ignore
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -13,7 +16,7 @@ messages_file = data_path / 'bread_messages.txt'
|
|||
word_regex = re.compile(r'\W')
|
||||
|
||||
|
||||
def get_that_bread():
|
||||
def get_that_bread() -> str:
|
||||
try:
|
||||
bread_messages = messages_file.read_text().strip().splitlines()
|
||||
assert bread_messages
|
||||
|
@ -27,7 +30,7 @@ def get_that_bread():
|
|||
return random.choice(bread_messages)
|
||||
|
||||
|
||||
def increment_bread():
|
||||
def increment_bread() -> None:
|
||||
try:
|
||||
count = int(count_file.read_text().strip())
|
||||
except (IOError, TypeError, ValueError):
|
||||
|
@ -39,12 +42,13 @@ def increment_bread():
|
|||
|
||||
|
||||
@plugin.listener('bread')
|
||||
def bread(ctx):
|
||||
def bread(ctx: Bot.Message) -> Optional[plugin.Output]:
|
||||
words = set(word_regex.split(ctx.text.lower()))
|
||||
if 'bread' in words:
|
||||
increment_bread()
|
||||
if words == {'bread'}:
|
||||
return plugin.message(get_that_bread())
|
||||
return None
|
||||
|
||||
|
||||
@plugin.command(
|
||||
|
@ -53,7 +57,7 @@ def bread(ctx):
|
|||
ops=True,
|
||||
ops_msg='This command is restricted to breadpunk admins.'
|
||||
)
|
||||
def nukethebread(ctx):
|
||||
def nukethebread(ctx: Bot.Message) -> plugin.Output:
|
||||
count_file.write_text('0')
|
||||
return plugin.message('Bread count has been reset.')
|
||||
|
||||
|
@ -62,7 +66,7 @@ def nukethebread(ctx):
|
|||
'!breadcount',
|
||||
help_text='How many times did bakers say bread here?',
|
||||
)
|
||||
def breadcount(ctx):
|
||||
def breadcount(ctx: Bot.Message) -> plugin.Output:
|
||||
try:
|
||||
count = int(count_file.read_text().strip())
|
||||
except (IOError, TypeError, ValueError):
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
flake8>=3.7
|
||||
flake8~=3.9
|
||||
isort>=5.9
|
||||
mypy~=0.910
|
||||
types-PyYAML~=5.4.3
|
||||
|
|
12
setup.cfg
12
setup.cfg
|
@ -1,5 +1,11 @@
|
|||
[flake8]
|
||||
exclude = .git,__pycache__,docs,*.pyc,venv
|
||||
exclude=build,.cache,.eggs,.git,breadbot.egg-info,lib,bin
|
||||
# Override the errors that Flake8 ignores by default to lint very hard.
|
||||
# Only ignore W503, which is deprecated and conflicts with W504.
|
||||
ignore=W503
|
||||
|
||||
[doc8]
|
||||
ignore-path=**/*.txt,*.txt,*.egg-info,docs/_build,venv,.git
|
||||
[mypy]
|
||||
disallow_incomplete_defs=True
|
||||
disallow_untyped_defs=True
|
||||
check_untyped_defs=True
|
||||
no_implicit_optional=True
|
||||
|
|
Loading…
Reference in New Issue