-
Notifications
You must be signed in to change notification settings - Fork 3
/
lechbot.py
81 lines (67 loc) · 2.02 KB
/
lechbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import asyncio
import logging
from sys import stdout
import humanize
import sentry_sdk
from chanconfig import CHANS
from config import BRIDGE_BOTS, MAIN_CHAN, NICKNAME, PORT, SENTRY_DSN, SERVER
from ircbot import CLIBot, IRCBot
def main(loglevel, klass, options):
humanize.i18n.activate("fr_FR")
fmt = "%(levelname)7s %(asctime)s | %(module)s:%(funcName)s | %(message)s"
logging.basicConfig(stream=stdout, level=loglevel, format=fmt)
if SENTRY_DSN:
sentry_sdk.init(SENTRY_DSN, traces_sample_rate=1.0)
bot = klass(
NICKNAME,
CHANS,
bridge_bots=BRIDGE_BOTS,
main_chan=MAIN_CHAN,
local_only=options.local,
)
@bot.command(r"tg %s$" % NICKNAME)
def shut_up(msg):
"""Je meurs"""
bot.log.info("Shutting down; asked by " + msg.user.nick)
exit()
bot.connect(host=SERVER, port=PORT)
bot.log.info("Starting")
if bot.local_only:
bot.log.info(
"You are in local mode, we will not try to poll from"
" twitter, the incubator or any other distant api."
)
asyncio.get_event_loop().run_forever()
else:
asyncio.get_event_loop().run_forever()
if __name__ == "__main__":
import argparse
optparser = argparse.ArgumentParser(description="LechBot, le bot de #urlab")
optparser.add_argument(
"--irc",
"-i",
action="store_true",
dest="online",
default=False,
help="Connect to IRC",
)
optparser.add_argument(
"--debug",
"-d",
action="store_true",
dest="debug",
default=False,
help="Also output debug informations",
)
optparser.add_argument(
"--local",
"-l",
action="store_true",
dest="local",
default=False,
help="Don't try to connect to Twitter",
)
options = optparser.parse_args()
lvl = logging.DEBUG if options.debug else logging.INFO
klass = IRCBot if options.online else CLIBot
main(lvl, klass, options)