Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slash Commandを追加 #25

Merged
merged 6 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# まぜそば大陸

<div align="center">
![Screenshot](docs/images/screenshot.png)
</div>

[![GitHub Release Date](https://img.shields.io/github/release-date/kakakaya/mazesoba-continent?style=flat)](https://github.com/kakakaya/mazesoba-continent/releases)
[![GitHub Downloads (all assets, latest release)](https://img.shields.io/github/downloads/kakakaya/mazesoba-continent/latest/total?sort=semver&style=flat)](https://github.com/kakakaya/mazesoba-continent/releases)
[![GitHub License](https://img.shields.io/github/license/kakakaya/mazesoba-continent?style=flat)](https://github.com/kakakaya/mazesoba-continent?tab=MIT-1-ov-file#readme)
Expand All @@ -8,11 +14,11 @@

Out of respect for [ラーメン大陸](https://forest.watch.impress.co.jp/docs/news/559014.html).

# 簡単な使い方
## 簡単な使い方

初回起動すると「設定ファイルが未設定だよ」みたいなことを言うので、設定ファイルの場所を開いて `config.toml` で以下の内容を入力してください。

```
```toml
[Credential]
Identifier = "<ここにIdentifierを入れる>"
Password = "<ここにパスワードを入れる>"
Expand All @@ -21,5 +27,7 @@ Out of respect for [ラーメン大陸](https://forest.watch.impress.co.jp/docs/

Windows や Linux なら <kbd>Ctrl</kbd> + <kbd>Enter</kbd> macOS なら <kbd>Cmd</kbd> + <kbd>Enter</kbd> で投稿ができます。

# 複雑な使い方
そのうち書く
## 複雑な使い方

- [Slash Command](./docs/SLASH_COMMAND.md)
- "/help"
26 changes: 18 additions & 8 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"log/slog"
"net/http"
"os"
"os/exec"
goruntime "runtime"
"strings"
"time"

Expand Down Expand Up @@ -69,11 +71,6 @@ func (a *App) startup(ctx context.Context) {
}
}

func (a *App) onDomReady(ctx context.Context) {
slog.Info("Emitting OnDomReady", a.config)
runtime.EventsEmit(ctx, "OnDomReady", "hello")
}

func (a *App) beforeClose(ctx context.Context) bool {
err := a.scheduler.Shutdown()
if err != nil {
Expand Down Expand Up @@ -169,8 +166,21 @@ func (a *App) OpenLogDirectory() error {
return openDirectory(f)
}

func (a *App) GetVersion() string {
return Version
func OpenURL(url string) error {
var cmd string
var args []string

switch goruntime.GOOS {
case "windows":
cmd = "cmd"
args = []string{"/c", "start"}
case "darwin":
cmd = "open"
default:
cmd = "xdg-open"
}
args = append(args, url)
return exec.Command(cmd, args...).Start()
}

func (a *App) SetXRPCClient() error {
Expand Down Expand Up @@ -204,7 +214,7 @@ func (a *App) SetXRPCClient() error {
result, dialogErr := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "認証に失敗したよ",
Message: fmt.Sprintf("%sへの認証に失敗しました。\nIDとパスワードを確認してね。\nこのまま沈没するけど、設定ファイルの場所を開く?", cred.Host),
Message: fmt.Sprintf("%sへの認証に失敗しました。\nIDとパスワードとインターネット接続を確認してね。\n設定ファイルの場所を開く?", cred.Host),
DefaultButton: "Yes",
})

Expand Down
128 changes: 122 additions & 6 deletions continent.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,126 @@
package main

// getSpecialCommand ...
func getSpecialCommand(text string) string {
switch text {
case "@バージョン":
return "未実装"
import (
"fmt"
"net/http"
"strings"

"github.com/wailsapp/wails/v2/pkg/runtime"
)

func (a *App) DispatchCommand(text string) string {
a.logger.Debug("dispatchcommand", "text", text)
words := strings.Fields(text)
if len(words) < 1 {
return a.Post(text)
}
action := words[0]
switch action {
case "/help":
{
if len(words) < 2 {
OpenURL("https://github.com/kakakaya/mazesoba-continent/blob/main/README.md")
}
switch words[1] {
case "config":
{
OpenURL("https://github.com/kakakaya/mazesoba-continent/tree/main/docs/CONFIG.md")
}
case "command":
{
OpenURL("https://github.com/kakakaya/mazesoba-continent/tree/main/docs/SLASH_COMMAND.md")
}
default:
{
OpenURL("https://github.com/kakakaya/mazesoba-continent/blob/main/README.md")
}
}
return ""
}
case "/open":
{
if len(words) < 2 {
return "🍜「何を開く?アジ?」"
}
switch words[1] {
case "config":
{
a.OpenConfigDirectory()
}
case "log":
{
a.OpenLogDirectory()
}
case "profile":
{
handle_or_did := words[2]
OpenURL(fmt.Sprintf("https://bsky.app/profile/%s", handle_or_did))
}
case "search", "s":
{
if len(words) < 3 {
return "🍜「検索ワードを指定してね」"
}
req, err := http.NewRequest("GET", "https://bsky.app/search", nil)
if err != nil {
a.logger.Warn("error making HTTP request", "error", err)
return ""
}

q := req.URL.Query()
q.Add("q", strings.Join(words[2:], " "))
req.URL.RawQuery = q.Encode()

OpenURL(req.URL.String())
}
default:
{
OpenURL(words[1]) // NOTE: TBC
}
}
return ""
}
case "/post":
{
if len(words) < 2 {
return "🍜「サブコマンドを指定してね。 /post version とか」"
}
switch words[1] {
case "chikuwa", "ckw":
{
return a.Chikuwa("ちくわ。")
}
case "earthquake", "eq":
{
return a.Chikuwa("地震だ!")
}
case "version", "ver":
{
return a.Chikuwa(fmt.Sprintf("まぜそば大陸バージョン%sが浮上中", Version))
}
}
}
case "/quit":
{
runtime.Quit(a.ctx)
}
case "/mzsb": // hidden functions
{
if len(words) < 2 {
return ""
}
switch words[1] {
case "egosearch", "egs":
{
OpenURL("https://bsky.app/search?q=%E3%81%BE%E3%81%9C%E3%81%9D%E3%81%B0%E5%A4%A7%E9%99%B8")
}
}
return ""
}
default:
{
return a.Post(text)
}
}
return text
return ""
}
32 changes: 32 additions & 0 deletions docs/SLASH_COMMAND.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Slash Command

`/open search まぜそば大陸` ってポストしてみよう

## って何

DiscordとかSlackにあるみたいなやつ。

## コマンド一覧

| COMMAND | ARGS | ACTION | SHORTCUT |
|------------------------------------|---------------------------------|------------------------------|------------------------------|
| `/help` | | [README.md](/README.md) を開く | |
| `/help command` | | これを開く | |
| `/help config` | | [CONFIG.md](./CONFIG.md) を開く | |
| `/open config` | | 設定ファイルの場所を開く | <kbd>Ctrl</kbd>+<kbd>,</kbd> |
| `/open log` | | ログの場所を開く | <kbd>Ctrl</kbd>+<kbd>.</kbd> |
| `/open profile (<HANDLE> / <DID>)` | HANDLE / DID : ユーザーのハンドル名またはDID | ユーザープロフィールを開く |
| `/open search <TEXT>` | TEXT : 検索したい文言(v10時点では) | ユーザープロフィールを開く | |
| `/post chikuwa` | | ちくわ。 | |
| `/post earthquake` | | 地震だ! | |
| `/post version` | | 今使っているバージョン | |
| `/quit` | | 沈没 | <kbd>Ctrl</kbd>+<kbd>q</kbd> |

<!--
/open weather 100-0001
/set footer #spam
/set header #eggs
/unset footer
/unset header
/mzsb version
-->
Binary file added docs/images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 8 additions & 23 deletions frontend/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import {
Chikuwa,
Post,
DispatchCommand,
} from '../wailsjs/go/main/App.js'
import {
EventsOn,
Expand All @@ -22,15 +21,7 @@
let placeholder = Math.random() > 0.5 ? "最近どう?" : "どう最近?"

function post() {
Post(text).then(result => {
placeholder = result
text = ""
})
}

function chikuwa() {
const c = text ? text : "ちくわ。"
Chikuwa(c).then(result => {
DispatchCommand(text).then(result => {
placeholder = result
text = ""
})
Expand All @@ -57,7 +48,7 @@

function setBackgroundColor(r, g, b, a) {
const newBackgroundStyle = `background-color: rgba(${r}, ${g}, ${b}, ${a});`
// FIXME: implement, I've tired for now
LogInfo(newBackgroundStyle)
}

// Setup Events
Expand All @@ -67,19 +58,13 @@
EventsOn("call-post", () => {
post()
})
EventsOn("call-chikuwa", () => {
chikuwa()
})
EventsOn("OnDomReady", (args) => {
LogInfo("OnDomReady");
LogInfo(args);
EventsOn("call-ondomready", (config) => {
LogInfo(JSON.stringify(config))
setBackgroundColor(config.Window.BackgroundR, config.Window.BackgroundG, config.Window.BackgroundB, config.Window.BackgroundA)
})
</script>

<main style="--wails-draggable:drag">
<div class="input-box" id="input">
<textarea autocomplete="off" bind:value={text} on:input={onChange} placeholder={placeholder} id="inputbox" />
<p id="char-counter" class="char-count">{charCounter}</p>
</div>
<p id="input-length"></p>
<textarea autocomplete="off" bind:value={text} on:input={onChange} placeholder={placeholder} id="inputbox" />
<p id="char-counter" class="char-count">{charCounter}</p>
</main>
4 changes: 2 additions & 2 deletions frontend/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ body {
#inputbox {
background: transparent;
color: white;
height: 95%;
width: 95%;
height: 95vh;
width: 95vw;
resize: none;
border: none;
outline: none;
Expand Down
2 changes: 1 addition & 1 deletion frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

export function Chikuwa(arg1:string):Promise<string>;

export function GetVersion():Promise<string>;
export function DispatchCommand(arg1:string):Promise<string>;

export function OpenConfigDirectory():Promise<void>;

Expand Down
4 changes: 2 additions & 2 deletions frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export function Chikuwa(arg1) {
return window['go']['main']['App']['Chikuwa'](arg1);
}

export function GetVersion() {
return window['go']['main']['App']['GetVersion']();
export function DispatchCommand(arg1) {
return window['go']['main']['App']['DispatchCommand'](arg1);
}

export function OpenConfigDirectory() {
Expand Down
22 changes: 5 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,19 @@ func main() {
// menu ================
AppMenu := menu.NewMenu()
FileMenu := AppMenu.AddSubmenu("ファイル")
FileMenu.AddText("沈没", keys.Key("Escape"), func(_ *menu.CallbackData) {
FileMenu.AddText("沈没", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
runtime.Quit(app.ctx)
})
FileMenu.AddText("Post", keys.CmdOrCtrl("Enter"), func(_ *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "call-post")
})
FileMenu.AddText("設定の場所を開く", keys.CmdOrCtrl(","), func(_ *menu.CallbackData) {
app.OpenConfigDirectory()
})
FileMenu.AddText("ログの場所を開く", keys.CmdOrCtrl("."), func(_ *menu.CallbackData) {
app.OpenLogDirectory()
})

CommandMenu := AppMenu.AddSubmenu("技")
CommandMenu.AddText("Post", keys.CmdOrCtrl("Enter"), func(_ *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "call-post")
})
CommandMenu.AddText("ちくわ。", keys.OptionOrAlt("c"), func(_ *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "call-chikuwa")
})
CommandMenu.AddText("地震だ!", keys.OptionOrAlt("F9"), func(_ *menu.CallbackData) {
app.Chikuwa("地震だ!")
})
CommandMenu.AddSubmenu("バージョン")
CommandMenu.AddText("バージョン", keys.OptionOrAlt("v"), func(_ *menu.CallbackData) {
app.Chikuwa("")
})
// BlueskyCommandMenu := CommandMenu.AddSubmenu("Bluesky")
WindowMenu := AppMenu.AddSubmenu("Window")
WindowMenu.AddText("中央に移動する", nil, func(_ *menu.CallbackData) {
Expand Down Expand Up @@ -109,7 +98,6 @@ func main() {
BackgroundColour: &options.RGBA{R: 48, G: 48, B: 48, A: 0},

OnStartup: app.startup,
OnDomReady: app.onDomReady,
OnBeforeClose: app.beforeClose,
Menu: AppMenu,
Bind: []interface{}{
Expand Down Expand Up @@ -143,6 +131,6 @@ func main() {
})

if err != nil {
app.logger.Warn("error on app close: ", err.Error())
app.logger.Warn("error on app close", "error", err.Error())
}
}
Loading