93 行
3.3 KiB
C
93 行
3.3 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
#include <weechat/weechat-plugin.h>
|
|
#include <curl/curl.h>
|
|
#include <cjson/cJSON.h>
|
|
|
|
#include "commands.h"
|
|
#include "api.h"
|
|
#include "meinfo.h"
|
|
#include "roomsinfo.h"
|
|
#include "rooms.h"
|
|
|
|
WEECHAT_PLUGIN_NAME("chatwork");
|
|
WEECHAT_PLUGIN_DESCRIPTION("Chatwork対応");
|
|
WEECHAT_PLUGIN_AUTHOR("洩矢諏訪子 <suwako@076.moe>");
|
|
WEECHAT_PLUGIN_VERSION("0.1");
|
|
WEECHAT_PLUGIN_LICENSE("GPL3");
|
|
|
|
int chatwork_command_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) {
|
|
const char *token = weechat_config_string(chatwork_config_token);
|
|
if (!token || strlen(token) == 0) {
|
|
weechat_printf(buffer, "トークンを見つけられませんでした。\n");
|
|
return WEECHAT_RC_ERROR;
|
|
}
|
|
|
|
if (argc < 2 || (argc == 2 && strcmp(argv[1], "help") == 0)) {
|
|
weechat_printf(buffer, "使い方: /chatwork me - ユーザー情報を表示\n");
|
|
weechat_printf(buffer, " /chatwork rooms - 部屋を表示\n");
|
|
weechat_printf(buffer, " /chatwork join 部屋番号 - 部屋に参加\n");
|
|
weechat_printf(buffer, " /chatwork upload パス - ファイルをアップロードする\n");
|
|
return WEECHAT_RC_OK;
|
|
}
|
|
|
|
if (strcmp(argv[1], "me") == 0) {
|
|
getMeInfo(buffer, token);
|
|
} else if (strcmp(argv[1], "rooms") == 0) {
|
|
getRoomsInfo(buffer, token);
|
|
} else if (strcmp(argv[1], "join") == 0) {
|
|
if (argc == 3) {
|
|
getRoom(buffer, token, atoi(argv[2]));
|
|
} else {
|
|
weechat_printf(buffer, "部屋番号をご入力下さい。\n");
|
|
}
|
|
} else if (strcmp(argv[1], "upload") == 0) {
|
|
if (argc == 3) {
|
|
getRoom(buffer, token, atoi(argv[2]));
|
|
} else {
|
|
weechat_printf(buffer, "パスをご入力下さい。\n");
|
|
}
|
|
} else {
|
|
weechat_printf(buffer, "不明なコマンド:%s\n", argv[1]);
|
|
weechat_printf(buffer, "すべてのコマンドを表示するには、/chatwork helpを実行して下さい。\n");
|
|
}
|
|
|
|
return WEECHAT_RC_OK;
|
|
}
|
|
|
|
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) {
|
|
weechat_plugin = plugin;
|
|
|
|
// コンフィグファイル
|
|
chatwork_config_file = weechat_config_new("weechat-chatwork", NULL, NULL, NULL);
|
|
if (!chatwork_config_file) {
|
|
return WEECHAT_RC_ERROR;
|
|
}
|
|
|
|
struct t_config_section *section;
|
|
section = weechat_config_new_section(chatwork_config_file, "general", 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
if (!section) {
|
|
weechat_config_free(chatwork_config_file);
|
|
return WEECHAT_RC_ERROR;
|
|
}
|
|
|
|
chatwork_config_token = weechat_config_new_option(chatwork_config_file, section, "token", "string", "Chatwork API token.", NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
if (weechat_config_read(chatwork_config_file) != WEECHAT_CONFIG_READ_OK) {
|
|
weechat_printf(NULL, "%s コンフィグファイルを読み込みに失敗。", weechat_prefix("error"));
|
|
return WEECHAT_RC_ERROR;
|
|
}
|
|
|
|
// /chatworkコマンドを登録
|
|
weechat_hook_command("chatwork", "Chatwork コマンド", "[arguments]", "コマンドの説明", NULL, &chatwork_command_cb, NULL, NULL);
|
|
|
|
return WEECHAT_RC_OK;
|
|
}
|
|
|
|
int weechat_plugin_end (struct t_weechat_plugin *plugin) {
|
|
// TODO
|
|
weechat_config_free(chatwork_config_file);
|
|
return WEECHAT_RC_OK;
|
|
}
|