Compare commits
3 Commits
8f0ae10fd4
...
10fdf5f33c
Author | SHA1 | Date | |
---|---|---|---|
10fdf5f33c | |||
859c164fea | |||
8466cd62a0 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.idea/
|
||||
*.env
|
||||
*.log
|
||||
*.pyc
|
||||
.idea/
|
||||
|
@ -43,3 +43,6 @@ logging.config.dictConfig({
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
# module specific configs
|
||||
MARKOV_CONTEXT = os.environ.get('HITOMI_MARKOV_CONTEXT', 'hitomi')
|
||||
|
@ -23,7 +23,6 @@ class Dice(commands.Cog):
|
||||
logger.info("rolling dice: %s", dice)
|
||||
try:
|
||||
response = dr_botzo.post('/dice/rpc/roll/', json={'dice': dice})
|
||||
response.raise_for_status()
|
||||
logger.debug("result of rolling dice: HTTP %s, %s", response.status_code, response.text)
|
||||
output = re.sub(r'(\d+)(.*?\s+)(\(.*?\))', r'**\1**\2\3', response.json()['result'])
|
||||
output = '\n'.join(output.split('; '))
|
||||
|
38
hitomi/markov.py
Normal file
38
hitomi/markov.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""Commands for populating and retrieving markov chains, for silly chatter."""
|
||||
import logging
|
||||
from urllib.parse import quote
|
||||
|
||||
from hitomi import bot, config
|
||||
from hitomi.backends import dr_botzo, DrBotzoError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@bot.listen(name='on_message')
|
||||
async def on_message_learn(message):
|
||||
"""Learn lines, potentially also respond to them."""
|
||||
logger.info("learning to %s: '%s'", config.MARKOV_CONTEXT, message.clean_content)
|
||||
try:
|
||||
response = dr_botzo.post('/markov/rpc/context/{context}/learn/'.format(context=quote(config.MARKOV_CONTEXT)),
|
||||
json={'line': message.clean_content})
|
||||
logger.debug("succeeded to learn '%s'", response.json()['line'])
|
||||
except DrBotzoError as drex:
|
||||
logger.exception("received an error from dr.botzo attempting to learn to %s: %s", config.MARKOV_CONTEXT, drex)
|
||||
|
||||
|
||||
@bot.listen(name='on_message')
|
||||
async def on_message_reply(message):
|
||||
"""Learn lines, potentially also respond to them."""
|
||||
if bot.user in message.mentions:
|
||||
logger.info("I was addressed, going to reply with chatter")
|
||||
await message.channel.trigger_typing()
|
||||
try:
|
||||
response = dr_botzo.post('/markov/rpc/context/{context}/generate/'
|
||||
''.format(context=quote(config.MARKOV_CONTEXT)),
|
||||
json={'topics': message.clean_content.split(' ')})
|
||||
reply = response.json()['generated_line']
|
||||
logger.info("replying to %s with '%s'", message.channel, reply)
|
||||
await message.channel.send(reply)
|
||||
except DrBotzoError as drex:
|
||||
logger.exception("received an error from dr.botzo attempting to reply to %s: %s",
|
||||
message.clean_content, drex)
|
Loading…
Reference in New Issue
Block a user