commit f69721f642f08311c05243c78d1256a4bc3dd721 Author: Kyle Brown Date: Tue May 4 17:08:48 2021 -0700 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e1b7a3a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +.idea +*.log +tmp/ + + +src/apikey.nim +boardsourcebot diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d5e10b5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM nimlang/nim:onbuild +ENTRYPOINT ["./boardsourcebot"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f7c7f09 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +## +# Discord bot for boardsource +# +# @file +# @version 0.1 + +SRC = boardsourcebot.nim +SRCDIR = src +BIN = boardsourcebot +SERVICE_FILE = boardsourcebot.service +INSTALL_DIR = /opt/boardsourcebot +SERVICE_DIR = /usr/lib/systemd/system/ + +debug: + nimble build '-d:ssl --cc:clang' + +release: + nimble build '-d:ssl --cc:clang -d:release' + +clean: + rm -f ./${BIN} + +pretty: + nimpretty ${SRCDIR}/${SRC} + +run: + ./${BIN} + +install: + mkdir -P /opt/${INSTALL_DIR} + cp ./${BIN} /opt/${INSTALL_DIR}/${BIN} + cp ${SERVICE_FILE} ${SERVICE_DIR}/${SERVICE_FILE} + + +# end diff --git a/README.md b/README.md new file mode 100644 index 0000000..8863f56 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Boardsource bot +Boardsourcebot is designed to make the lives or the boardsource mods easier to help deal with repeat questions + +## Requirementss +1. Install Nim using [choosenim](https://github.com/dom96/choosenim) or [Nim's website](https://nim-lang.org/install.html) +2. Install Nimble from [numble](https://github.com/nim-lang/nimble) + +##Building +`make release` or `make debug` diff --git a/boardsourcebot.nimble b/boardsourcebot.nimble new file mode 100644 index 0000000..6d23834 --- /dev/null +++ b/boardsourcebot.nimble @@ -0,0 +1,14 @@ +# Package + +version = "0.1.0" +author = "Kyle Brown" +description = "Boardsource discord bot" +license = "MIT" +srcDir = "src" +bin = @["boardsourcebot"] + + +# Dependencies + +requires "nim >= 1.4.6" +requires "dimscord >= 1.2.5" diff --git a/boardsourcebot.service b/boardsourcebot.service new file mode 100755 index 0000000..a18d0c2 --- /dev/null +++ b/boardsourcebot.service @@ -0,0 +1,9 @@ +[Unit] +Description=boardsourcebot + +[Service] +WorkingDirectory=/opt/boardsourcebot +ExecStart=/opt/boardsourcebot/boardsourcebot + +[Install] +WantedBy=multi-user.target diff --git a/dockerrun.sh b/dockerrun.sh new file mode 100755 index 0000000..b9ba82f --- /dev/null +++ b/dockerrun.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +docker build -t boardsourcebot . +docker run --rm boardsourcebot diff --git a/nim.cfg b/nim.cfg new file mode 100644 index 0000000..521e21d --- /dev/null +++ b/nim.cfg @@ -0,0 +1 @@ +-d:ssl diff --git a/src/apikey.nim.example b/src/apikey.nim.example new file mode 100644 index 0000000..3cdc115 --- /dev/null +++ b/src/apikey.nim.example @@ -0,0 +1,2 @@ +const prefix = "!" +const apikey = "" diff --git a/src/boardsourcebot.nim b/src/boardsourcebot.nim new file mode 100644 index 0000000..c1484dd --- /dev/null +++ b/src/boardsourcebot.nim @@ -0,0 +1,67 @@ +include apikey +import dimscord, asyncdispatch, options, strformat, strutils + +let discord = newDiscordClient(apikey) + +# Handle event for on_ready. +proc onReady(s: Shard, r: Ready) {.event(discord).} = + echo "Ready as " & $r.user + +# Handle event for message_create. +proc messageCreate(s: Shard, m: Message) {.event(discord).} = + if m.author.bot: return + + if m.content == fmt"{prefix}help": + let msg = await discord.api.sendMessage(m.channel_id, + fmt""" + Commands are prefixed with {prefix}. Avaliable commands are help, brokenkey, + buildguide, trrs, restock, shipping, oled, configure, elitec, sockets + """.dedent.splitlines.join(" ")) + + elif m.content == fmt"{prefix}brokenkey": + let msg = await discord.api.sendMessage(m.channel_id, "Broken key tips can be found here") + let link = await discord.api.sendMessage(m.channel_id, + "https://discord.com/channels/704394060390989834/705657159639105626/798051589004197938") + + elif m.content == fmt"{prefix}buildguide": + let msg = await discord.api.sendMessage(m.channel_id, "Build guides can be found here") + let link = await discord.api.sendMessage(m.channel_id, + "https://discord.com/channels/704394060390989834/705657159639105626/790728181857910854") + + elif m.content == fmt"{prefix}trrs": + let msg = await discord.api.sendMessage(m.channel_id, "TRRS jacks are included with the PCB, as are the reset buttons") + + elif m.content == fmt"{prefix}restock" or m.content == + fmt"{prefix}shipping": + let gif = await discord.api.sendMessage(m.channel_id, + "https://media1.tenor.com/images/28cf6532c043be996d04c00ec2ac3246/tenor.gif?itemid=2088319") + let msg = await discord.api.sendMessage(m.channel_id, + "Shipping is backup up worldwide and we can not give estimates at the current time") + + elif m.content == fmt"{prefix}oled": + let msg = await discord.api.sendMessage(m.channel_id, "OLED help can be found here") + let link = await discord.api.sendMessage(m.channel_id, + "https://discord.com/channels/704394060390989834/755980550539313293/790417018822197289") + + elif m.content == fmt"{prefix}configure": + let msg = await discord.api.sendMessage(m.channel_id, + """ + Hitting configure will add at least one of each item you NEED For a working + keyboard, not including switches or keycaps. For example, it will include 1 + PCB or pair of PCBs for splits. You may want to add or change items to + customize it for your needs or desires though! + """.dedent.splitlines.join(" ")) + + elif m.content == fmt"{prefix}elitec": + let msg = await discord.api.sendMessage(m.channel_id, + """ + The elite C uses a type-C port as opposed to microUSB making it less prone + to breaking, as well as having a better bootloader, which is especially + important for linux users. + """.dedent.splitlines.join(" ")) + + elif m.content == fmt"{prefix}sockets": + let msg = await discord.api.sendMessage(m.channel_id, "Socket information and links can be found here") + let link = await discord.api.sendMessage(m.channel_id, "https://discord.com/channels/704394060390989834/705657159639105626/752342450047156245") + +waitFor discord.startSession()