from slackrest.app import SlackrestApp
from slackrest.command import Visibility, Method
import json


class GetPuzzle:
    pattern = '!nian'
    url_format = '/puzzle'
    visibility = Visibility.Any
    body = None
    method = Method.GET


class SetPuzzle:
    pattern = '!sättnian {nian}'
    url_format = '/puzzle'
    visibility = Visibility.Any
    method = Method.POST

    @classmethod
    def body(cls, nian, **kwargs):
        return json.dumps({'puzzle': nian})


class ListUnsolution:
    pattern = '!olösningar'
    url_format = '/unsolution/{user_id}'
    visibility = Visibility.Private
    method = Method.GET
    body = None


class AddUnsolution:
    pattern = '!olösning {unsolution}'
    url_format = '/unsolution/{user_id}'
    visibility = Visibility.Private
    method = Method.POST

    @classmethod
    def body(cls, unsolution, **kwargs):
        return json.dumps({'unsolution': unsolution})


class CheckSolution:
    pattern = '{solution}'
    url_format = '/solution/{solution}'
    visibility = Visibility.Private
    method = Method.POST

    @classmethod
    def body(cls, user_id, **kwargs):
        return json.dumps({'user': user_id})


class NiancatSlack(SlackrestApp):
    def __init__(self, base_url, notification_channel_id):
        commands = [GetPuzzle, SetPuzzle, ListUnsolution, AddUnsolution, CheckSolution]
        SlackrestApp.__init__(self, base_url, commands, notification_channel_id)


if __name__ == "__main__":
    app = NiancatSlack('http://niancat-chat/v1', '#konsulatet')
    app.run_forever()

@@ -546,34 +546,36 @@
 nsolution/%7Buser_
-id
+name
 %7D'%0A    visibilit
@@ -735,18 +735,20 @@
 n/%7Buser_
-id
+name
 %7D'%0A    v
@@ -1108,18 +1108,20 @@
 s, user_
-id
+name
 , **kwar
@@ -1165,18 +1165,20 @@
 ': user_
-id
+name
 %7D)%0A%0A%0Acla

change user id to user name in niancat-slack