-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1b224c1
Showing
24 changed files
with
5,696 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# https://releases.llvm.org/6.0.0/tools/clang/docs/ClangFormatStyleOptions.html | ||
|
||
# LLVM 스타일을 기반으로 한 C++ 코딩 스타일. | ||
BasedOnStyle: LLVM | ||
Language: Cpp | ||
|
||
# 공백 설정 | ||
SpaceAfterCStyleCast: true | ||
SpaceAfterTemplateKeyword: false | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInContainerLiterals: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
|
||
# 들여쓰기 설정 | ||
IndentCaseLabels: true | ||
IndentWidth: 4 | ||
IndentWrappedFunctionNames: false | ||
TabWidth: 4 | ||
UseTab: false | ||
|
||
# 코드 정렬 설정 | ||
AlignAfterOpenBracket: Align | ||
# AlignConsecutiveAssignments: false | ||
# AlignConsecutiveDeclarations: false | ||
AlignEscapedNewlines: Left | ||
AlignTrailingComments: true | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AlwaysBreakTemplateDeclarations: false | ||
# BinPackArguments: false | ||
# BinPackParameters: false | ||
# BreakBeforeBraces: Attach | ||
BreakBeforeInheritanceComma: false | ||
SortIncludes: true | ||
SortUsingDeclarations: true | ||
|
||
# 포인터 변수 스타일 설정 | ||
DerivePointerAlignment: false | ||
PointerAlignment: Right | ||
|
||
# 나머지 스타일 설정 | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
ColumnLimit: 0 | ||
MaxEmptyLinesToKeep: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 로그 파일 | ||
*.log | ||
|
||
# 백업 파일과 설정 파일 | ||
*.bak | ||
*.manifest | ||
|
||
# 오브젝트 파일 | ||
*.o | ||
|
||
# 정적 라이브러리 파일 | ||
*.a | ||
*.lib | ||
|
||
# 빌드 결과물이 저장된 폴더 | ||
**/.vs/ | ||
**/bin/ | ||
**/build/ | ||
**/**/Debug/ | ||
**/**/Release/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# | ||
# Copyright (c) 2022 jdeokkim | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
# | ||
|
||
.PHONY: all clean | ||
|
||
_COLOR_BEGIN := $(shell tput setaf 13) | ||
_COLOR_END := $(shell tput sgr0) | ||
|
||
PROJECT_NAME := saerom | ||
PROJECT_FULL_NAME := jdeokkim/saerom | ||
|
||
PROJECT_PREFIX := $(_COLOR_BEGIN)$(PROJECT_FULL_NAME):$(_COLOR_END) | ||
|
||
BINARY_PATH := bin | ||
INCLUDE_PATH := include | ||
RESOURCE_PATH := res | ||
SOURCE_PATH := src | ||
|
||
INCLUDE_PATH += $(SOURCE_PATH)/external | ||
|
||
SOURCES := \ | ||
$(SOURCE_PATH)/bot.c \ | ||
$(SOURCE_PATH)/info.c \ | ||
$(SOURCE_PATH)/json.c \ | ||
$(SOURCE_PATH)/krdict.c \ | ||
$(SOURCE_PATH)/papago.c \ | ||
$(SOURCE_PATH)/utils.c \ | ||
$(SOURCE_PATH)/yxml.c \ | ||
$(SOURCE_PATH)/main.c | ||
|
||
OBJECTS := $(SOURCES:.c=.o) | ||
|
||
TARGETS := $(BINARY_PATH)/$(PROJECT_NAME) | ||
|
||
CC := gcc | ||
CFLAGS := -D_DEFAULT_SOURCE -g $(INCLUDE_PATH:%=-I%) -O2 -std=gnu99 | ||
LDLIBS := -ldl -lcurl -ldiscord -lpthread -lsigar | ||
|
||
all: pre-build build post-build | ||
|
||
pre-build: | ||
@echo "$(PROJECT_PREFIX) Using: '$(CC)' to build this project." | ||
|
||
build: $(TARGETS) | ||
|
||
$(SOURCE_PATH)/%.o: $(SOURCE_PATH)/%.c | ||
@echo "$(PROJECT_PREFIX) Compiling: $@ (from $<)" | ||
@$(CC) -c $< -o $@ $(CFLAGS) | ||
|
||
$(TARGETS): $(OBJECTS) | ||
@mkdir -p $(BINARY_PATH) | ||
@echo "$(PROJECT_PREFIX) Linking: $(TARGETS)" | ||
@$(CC) $(OBJECTS) -o $(TARGETS) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(WEBFLAGS) | ||
|
||
post-build: | ||
@echo "$(PROJECT_PREFIX) Build complete." | ||
|
||
clean: | ||
@echo "$(PROJECT_PREFIX) Cleaning up." | ||
@rm -rf $(BINARY_PATH)/* | ||
@rm -rf $(SOURCE_PATH)/*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# saerom | ||
|
||
|
||
[![version badge](https://img.shields.io/github/v/release/jdeokkim/saerom?color=orange&include_prereleases)](https://github.com/jdeokkim/saerom/releases) | ||
[![code-size badge](https://img.shields.io/github/languages/code-size/jdeokkim/saerom?color=green)](https://github.com/jdeokkim/saerom) | ||
[![license badge](https://img.shields.io/github/license/jdeokkim/saerom?color=brightgreen)](https://github.com/jdeokkim/saerom/blob/main/LICENSE) | ||
|
||
A C99 Discord bot for Korean learning servers. | ||
|
||
## Commands | ||
|
||
| Name | Description | | ||
| ------- | ---------------------------------------------------------------------------------------------------------------------------------------------| | ||
| `/info` | Show information about this bot | | ||
| `/krd` | Search the given text in the [Basic Korean Dictionary](https://krdict.korean.go.kr/), published by the National Institute of Korean Language | | ||
| `/ppg` | Translate the given text between two languages using [NAVER™ Papago NMT API](https://developers.naver.com/docs/papago/README.md) | | ||
|
||
## Screenshots | ||
|
||
### `/info` | ||
|
||
<details> | ||
<summary>Screenshot</summary> | ||
|
||
<img src="res/images/screenshot-info.png" alt="/info"> | ||
</details> | ||
|
||
### `/krd` | ||
|
||
<details> | ||
<summary>Screenshot</summary> | ||
|
||
<img src="res/images/screenshot-krd.png" alt="/krd"> | ||
</details> | ||
|
||
### `/ppg` | ||
|
||
<details> | ||
<summary>Screenshot</summary> | ||
|
||
<img src="res/images/screenshot-ppg.png" alt="/ppg"> | ||
</details> | ||
|
||
## Prerequisites | ||
|
||
- GCC version 9.4.0+ | ||
- GNU Make version 4.1+ | ||
- CMake version 3.22.0+ | ||
- Git version 2.17.1+ | ||
- libcurl4 version 7.58.0+ (with OpenSSL flavor) | ||
|
||
```console | ||
$ sudo apt install build-essential cmake git libcurl4-openssl-dev | ||
``` | ||
|
||
## Building | ||
|
||
This project uses [GNU Make](https://www.gnu.org/software/make) as the build system. | ||
|
||
1. Install [concord v2.0.1+](https://github.com/Cogmasters/concord). | ||
|
||
```console | ||
$ git clone https://github.com/Cogmasters/concord && cd concord | ||
$ make -j`nproc` | ||
$ sudo make install | ||
``` | ||
|
||
2. Then, install the latest version of [boundary/sigar](https://github.com/boundary/sigar). | ||
|
||
```console | ||
$ git clone https://github.com/boundary/sigar && cd sigar | ||
$ mkdir build && cd build | ||
$ cmake .. && make -j`nproc` | ||
$ sudo make install | ||
$ ldconfig | ||
``` | ||
|
||
3. Build this project with the following commands. | ||
|
||
```console | ||
$ git clone https://github.com/jdeokkim/saerom && cd saerom | ||
$ make | ||
``` | ||
|
||
4. Configure and run the bot. | ||
|
||
```console | ||
$ vim res/config.json | ||
$ ./bin/saerom | ||
``` | ||
|
||
## License | ||
|
||
GNU General Public License, version 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
Copyright (c) 2022 jdeokkim | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef SAEROM_H | ||
#define SAEROM_H | ||
|
||
#include <stdbool.h> | ||
|
||
#include <concord/cog-utils.h> | ||
#include <concord/discord.h> | ||
|
||
/* | 매크로 정의... | */ | ||
|
||
#define APPLICATION_NAME "jdeokkim/saerom" | ||
#define APPLICATION_VERSION "v0.1.0" | ||
#define APPLICATION_DESCRIPTION "A C99 Discord bot for Korean learning servers." | ||
#define APPLICATION_PROJECT_URL "https://github.com/jdeokkim/saerom" | ||
#define APPLICATION_ID 986954825176596498 | ||
|
||
#define DEVELOPER_NAME "Jaedeok Kim" | ||
#define DEVELOPER_ICON_URL "https://avatars.githubusercontent.com/u/28700668" | ||
|
||
#define MAX_FILE_SIZE 1024 | ||
#define MAX_STRING_SIZE 256 | ||
|
||
/* | 자료형 정의... | */ | ||
|
||
/* Discord 봇의 환경 설정을 나타내는 구조체. */ | ||
struct sr_config { | ||
unsigned char flags; | ||
struct { | ||
char api_key[MAX_STRING_SIZE]; | ||
} krdict; | ||
struct { | ||
char client_id[MAX_STRING_SIZE]; | ||
char client_secret[MAX_STRING_SIZE]; | ||
} papago; | ||
}; | ||
|
||
/* Discord 봇의 환경 설정 플래그를 나타내는 열거형. */ | ||
enum sr_flag { | ||
SR_FLAG_KRDICT = (1 << 0), | ||
SR_FLAG_PAPAGO = (1 << 1) | ||
}; | ||
|
||
/* | `bot` 모듈 함수... | */ | ||
|
||
/* Discord 봇을 초기화한다. */ | ||
void init_bot(int argc, char *argv[]); | ||
|
||
/* Discord 봇을 실행한다. */ | ||
void run_bot(void); | ||
|
||
/* Discord 봇에 할당된 메모리를 해제한다. */ | ||
void deinit_bot(void); | ||
|
||
/* `CURLV` 인터페이스를 반환한다. */ | ||
void *get_curlv(void); | ||
|
||
/* Discord 봇의 환경 설정 정보를 반환한다. */ | ||
struct sr_config *get_sr_config(void); | ||
|
||
/* Discord 봇의 CPU 사용량 (단위: 퍼센트)을 반환한다. */ | ||
double get_cpu_usage(void); | ||
|
||
/* Discord 봇의 메모리 사용량 (단위: 메가바이트)을 반환한다. */ | ||
double get_ram_usage(void); | ||
|
||
/* Discord 봇의 작동 시간 (단위: 밀리초)을 반환한다. */ | ||
uint64_t get_uptime(void); | ||
|
||
/* | `info` 모듈 함수... | */ | ||
|
||
/* `info` 모듈 명령어를 생성한다. */ | ||
void create_info_command(struct discord *client); | ||
|
||
/* `info` 모듈 명령어에 할당된 메모리를 해제한다. */ | ||
void release_info_command(struct discord *client); | ||
|
||
/* `info` 모듈 명령어를 실행한다. */ | ||
void run_info_command( | ||
struct discord *client, | ||
const struct discord_interaction *event | ||
); | ||
|
||
/* | `krdict` 모듈 함수... | */ | ||
|
||
/* `krdict` 모듈 명령어를 생성한다. */ | ||
void create_krdict_command(struct discord *client); | ||
|
||
/* `krdict` 모듈 명령어에 할당된 메모리를 해제한다. */ | ||
void release_krdict_command(struct discord *client); | ||
|
||
/* `krdict` 모듈 명령어를 실행한다. */ | ||
void run_krdict_command( | ||
struct discord *client, | ||
const struct discord_interaction *event | ||
); | ||
|
||
/* | `papago` 모듈 함수... | */ | ||
|
||
/* `papago` 모듈 명령어를 생성한다. */ | ||
void create_papago_command(struct discord *client); | ||
|
||
/* `papago` 모듈 명령어에 할당된 메모리를 해제한다. */ | ||
void release_papago_command(struct discord *client); | ||
|
||
/* `papago` 모듈 명령어를 실행한다. */ | ||
void run_papago_command( | ||
struct discord *client, | ||
const struct discord_interaction *event | ||
); | ||
|
||
/* | `utils` 모듈 함수... | */ | ||
|
||
/* 주어진 사용자의 프로필 사진 URL을 반환한다. */ | ||
const char *get_avatar_url(const struct discord_user *user); | ||
|
||
/* 주어진 경로에 위치한 파일의 내용을 반환한다. */ | ||
char *get_file_contents(const char *path); | ||
|
||
/* 두 문자열의 내용이 서로 같은지 확인한다. */ | ||
bool string_equals(const char *s1, const char *s2); | ||
|
||
#endif |
Oops, something went wrong.