Git Product home page Git Product logo

quotebot's Introduction

Quote Bot

Table of Contents

1 feature

1.1 quote

If someone send a Message Link to following channels, Quote Bot replies the content of that link.

  • TextChannel
  • ThreadChannel
  • VoiceChannel
  • NewsChannel (not tested)
  • StageChannel (not tested)

If you do not want Quote Bot to reply, you can escape this by wrapping a link with <>.
Example: <https://discord.com/channels/GUILD_ID/CHANNEL_ID/MESSAGE_ID>

1.2 command

!quote: prefix

option alias description
--version -v version

e.g. !quote -v

2 deploy

These are all kobi32768's notebook, but it may be helpful.
kobi32768 not support other environment.

> Windows
$ Ubuntu

2.1 distribute

> gradle distZip

2.2 scp

Move zipped distribute file on ~/quotebot with WinSCP

2.3 unzip

$ unzip quotebot-<version>,zip

2.4 systemd

2.4.1 update

Service restart

$ systemctl restart quotebot

2.4.2 setup

Automatically execute latest

Make shell script for bot starting

start-quotebot.sh:

#!/bin/bash

latest=`ls -drt /home/<user>/quotebot/*/ | tail -n 1`
cd $latest
export DISCORD_TOKEN="<YOUR-DISCORD-TOKEN-HERE>"
./bin/quotebot

Make service file
$ ~/micro /etc/systemd/system/quotebot.service

quotebot.service:

[Unit]
Description=QuoteBot
After=netwowrk.target

[Service]
Restart=always
ExecStart=/home/<user>/start-quotebot.sh

[Install]
WantedBy=multi-user.target

Reload systemctl
$ systemctl daemon-reload

2.4.3 utility

Check status
$ systemctl list-unit-files | grep quotebot

quotebot's People

Contributors

sayamame-beans avatar kobi32768 avatar anatawa12 avatar

Stargazers

 avatar  avatar Takehiro Ogura avatar

Watchers

 avatar  avatar Tony Lewis Hiroaki URAHAMA avatar  avatar

quotebot's Issues

DM対応について

現在、DMからQuoteBotに対してメッセージを送信した場合もメッセージ受信イベントが呼ばれるようになっています。
しかしながら、実際にはDMから送信された場合は想定されておらず、幾つかの処理が対応していません。
対応するようにしますか?

インラインコードやコードブロック内のリンクは無視したい

package io.github.kobi32768.quotebot
private val linkRegexWithValidCheck = Regex("""(?<!<)https://discord\.com/channels/\d{6,19}/\d{6,19}/\d{6,19}(?!>)""")
private val linkRegexWithoutValidCheck = Regex("""https://discord\.com/channels/\d{6,19}/\d{6,19}/\d{6,19}""")
private fun String.extractLinks(force: Boolean): Sequence<String> {
return (if (force) linkRegexWithoutValidCheck else linkRegexWithValidCheck)
.findAll(this)
.map { it.value }
}
fun String.extractIDs(force: Boolean): Sequence<MessageLink> = this.extractLinks(force)
.map { link ->
val (guildId, channelId, messageId) = link.removePrefix("https://discord.com/channels/").split('/')
MessageLink(guildId.toLong(), channelId.toLong(), messageId.toLong())
}
data class MessageLink(
val guildId: Long,
val channelId: Long,
val messageId: Long,
)

ちゃんとパースしないといけなくて微妙に面倒そう…

[feat-req] Clip 機能

Misskey の clip に近いような カテゴリ分けのできるピン留め機能

local / global があってもいいかも

どうも Discord は "メッセージの管理" 権限にピン留めも含まれているみたいで 削除されたくないけどピン留めしたいときに使えそう

TextChannel以外のチャンネルに対応(スレッド機能等)

内容

現状のQuote BotではDiscordのスレッド機能に対応していません。

考えられる対処法

現在使用されているバージョンのJDAがスレッド機能に対応していない可能性が高く、バージョンを上げる必要があると考えられます。
安定しているかは不明です。

そのため、#11 の対処を行うのであれば、JDA更新作業を同時に行うのが望ましいと考えます。
スレッド機能への対応はその後の方が良いと考えられます。

TimeZone, Locale を設定する

LANG=ja_JP.utf8
ZONE="Asia/Tokyo"

で固定しちゃってもいいんだけど多分変更できた方がうれしいと思う

ビルドに失敗する

version.txtに改行が混ざっていることで、ビルド時のファイル生成に失敗した模様

CIを追加する

最低限ビルドが通ることは確認するべきなはず。
今後テストを追加する前提でテストの実行も考えたい

埋め込みの内容も取得する

出来ても良いのかな、と少し思ったりしました(webhookで流れてくるものなどの内容が現状では拾えないため)

開発環境と本番環境を分離したい

環境変数でトークン設定したりすればよさげかな

Docker で手軽に開発できるようになることを期待してるけど その分本番環境でテストするのも困るので

downgrade to java 8

Currently, this project uses JDK 14, which is after EOL in many distributions of OpenJDK.

<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="14" project-jdk-type="JavaSDK">

However, in build.gradle.kts, target version is specified to Java 1.8.

kotlinOptions.jvmTarget = "1.8"

Java 8 is still supported on many distributions. (e.g. Zulu, Temurin, Semeru)
So I suggest to use Java 8 to build this project.

引用元情報にカテゴリ名を追加

現在は from: Ch名 (サーバー名) となっている部分を from: カテゴリ名 / Ch名 (サーバー名) にする提案です。
これにより、引用元がより把握しやすくなります。

コマンドのprefixで、直後には空白が続かない可能性がある

// Command
if (content.startsWith("!quote")) {
val commands = content.split(' ')
if (commands.containsAny("-v", "--version")) {
event.sendMessage("**Version: ** ${VersionHolder.version}")
printlog("Displayed version (${VersionHolder.version})", State.INFORMATION)
}
}

により、!quotebot -vなどでもコマンドが実行出来てしまう。

引用に失敗する

内容

everyoneでの閲覧が許可されているチャンネルであるにもかかわらず、

閲覧を禁止されているチャンネル
@everyoneは閲覧権限がありません。

と出力されてしまう。

試した内容と、それにより推測される原因

everyoneの標準ロール権限で閲覧可能なチャンネルの権限設定で、everyoneによる閲覧を明示的に許可してみた
→ 引用に成功した

これにより、チャンネルの権限設定で特に指定されていない(ロールの権限に従う)場合の権限確認が失敗していると考えられる。

Add description of quote-escape feature and VoiceChannel/ThreadChannel/NewsChannel/StageChannel Support

quotebot/readme.md

Lines 19 to 34 in 14dd115

## 1 feature
### 1.1 quote
If send the Message Link to text channel, Quote Bot reply content of link.
### 1.2 command
`!quote`: prefix
|option|alias|description|
| ---- | --- | --------- |
|`--version`|`-v`|version|
e.g. `!quote -v`

Note

Quotability in NewsChannel is not tested because we have no guild which has a NewsChannel. (it probably works...?)

特定のch等でalways forceしたい

(NSFWのchに自動で流れてくるようにしている情報があり、それを外の(自動転送先でない)chに持っていくのにforceしないといけないのが不便)

forceオプションでのサーバー超え引用に失敗する

内容

forceオプションを使用して別のサーバーから引用しようとした場合に、引用が行われない。

推測される原因

私のコミットですね…
forceオプションの使用可能条件を確認するためには、URLが参照する先のCh権限かURLが参照する先のサーバー管理者権限を知る必要があるのに対し、現在の実装では引用先の(QuoteBotが書き込む)Ch/サーバーのmemberを元に確認しようとするので失敗していると考えられます。

fun MessageData.isForceQuotable(): Boolean {
val channel = this.channel
val member = this.event.member!!
return member.hasPermission(channel, Permission.MANAGE_CHANNEL) || member.hasPermission(channel, Permission.MESSAGE_MANAGE) || member.hasPermission(channel, Permission.ADMINISTRATOR)
}

現在の状況

これに対して修正を試みていますが、Discordの仕様上、QuoteBotの使用に必要な設定が増えると思われます。
対象の設定はServer Members Intentの有効化です。

ログファイルの作成に失敗する

エラーログ

Exception in thread "main" java.io.FileNotFoundException: log/latest.txt (そのようなファイルやディレクトリはありません)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
        at kotlin.io.FilesKt__FileReadWriteKt.readText(FileReadWrite.kt:125)
        at kotlin.io.FilesKt__FileReadWriteKt.readText$default(FileReadWrite.kt:125)
        at io.github.kobi32768.quotebot.LoggerKt.writeLogFile(Logger.kt:34)
        at io.github.kobi32768.quotebot.LoggerKt.printlog(Logger.kt:28)
        at io.github.kobi32768.quotebot.LoggerKt.printlog$default(Logger.kt:7)
        at io.github.kobi32768.quotebot.LoggerKt.makeLogFile(Logger.kt:43)
        at io.github.kobi32768.quotebot.QuoteBot.start(Main.kt:37)
        at io.github.kobi32768.quotebot.MainKt.main(Main.kt:16)
        at io.github.kobi32768.quotebot.MainKt.main(Main.kt)

推測される原因

コミット chore: delete unused latest.txt によりlog/latest.txtが削除されたこと、また、log/latest.txtが存在する前提で配置されたwriteText()によりlog/latest.txtが作成される前に、printlog()が実行されていることが原因であると考えます。

fun makeLogFile() {
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss")
val time = LocalDateTime.now().format(formatter)
printlog("Log file created: $time", State.INFORMATION)
File("log/$time.txt").createNewFile()
// overwrite
File("log/latest.txt").writeText(time)
}

読み取り特化型オプションの提供?

Related: #47
サーバーごとの設定の中で、読み取り自由にする(持ち出しにforceオプションを不要にする)設定があると良さそう。
また、botに書き込み権限を持たせないようにした場合で、そのチャンネルにリンクを貼られても例外を吐かないようになっているか確認する。

URLの判別に問題

URL内の各種IDの桁数は固定ではなかった模様。
実際に現在は19桁のIDが確認でき、引用が不可能となっています。

use <> for disable quote instead of \

Current implementation ignores \-started URLs. In discord, <>-qouted URLs will not have thumbnail. So, I think it's better to use <>-quoted for disable quotebot.

Discord PTBへの対応

Discord PTBはDiscordのパブリックテスト版ですが、このクライアントから取得されたメッセージURLは通常と異なり、
https://ptb.discord.com/channels/~となることが判明しました。
そのため、これを引用可能にする必要があります。

また、アルファ版であるDiscord Canaryでも同様の事象が発生する可能性が考えられます。

token.txtがクラスパス上にないといけない。

この実装では、token.txtがクラスパス上にないといけません。

this.javaClass.classLoader
.getResourceAsStream("token.txt")!!
.reader()
.readText())

しかし、クラスパスは quotebot[.bat] によって自動設定されるため、ユーザーは設定しません。

token.txtをCWD等ユーザーが編集可能なディレクトリから読まなければいけません。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.