-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
10 changed files
with
184 additions
and
52 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
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
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
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
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
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
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,28 @@ | ||
package cn.jackding.xiaoyasync.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @Author Jack | ||
* @Date 2022/8/2 21:04 | ||
* @Version 1.0.0 | ||
*/ | ||
@Component | ||
public class Config { | ||
|
||
public static String tgToken; | ||
|
||
public static String tgUserId; | ||
|
||
@Value("${tgToken}") | ||
public void setTgToken(String tgToken) { | ||
Config.tgToken = tgToken; | ||
} | ||
|
||
@Value("${tgUserId}") | ||
public void setTgUserId(String tgUserId) { | ||
Config.tgUserId = tgUserId; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,21 +1,69 @@ | ||
package cn.jackding.xiaoyasync.tgbot; | ||
|
||
import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient; | ||
import org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer; | ||
import org.telegram.telegrambots.meta.api.objects.Update; | ||
import org.telegram.telegrambots.meta.generics.TelegramClient; | ||
import cn.jackding.xiaoyasync.SyncService; | ||
import cn.jackding.xiaoyasync.config.Config; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.telegram.abilitybots.api.bot.AbilityBot; | ||
import org.telegram.abilitybots.api.objects.Ability; | ||
import org.telegram.telegrambots.bots.DefaultBotOptions; | ||
|
||
import static org.telegram.abilitybots.api.objects.Locality.USER; | ||
import static org.telegram.abilitybots.api.objects.Privacy.CREATOR; | ||
|
||
/** | ||
* @Author Jack | ||
* @Date 2024/6/4 17:17 | ||
* @Date 2024/6/4 21:33 | ||
* @Version 1.0.0 | ||
*/ | ||
public class SyncBot implements LongPollingSingleThreadUpdateConsumer { | ||
private TelegramClient telegramClient = new OkHttpTelegramClient(""); | ||
public class SyncBot extends AbilityBot { | ||
|
||
|
||
public SyncBot() { | ||
super(Config.tgToken, ""); | ||
} | ||
|
||
public SyncBot(DefaultBotOptions options) { | ||
super(Config.tgToken, "", options); | ||
} | ||
|
||
@Override | ||
public void consume(Update update) { | ||
// TODO | ||
public long creatorId() { | ||
return Long.parseLong(Config.tgUserId); | ||
} | ||
|
||
public Ability sync() { | ||
return Ability.builder() | ||
.name("sync") | ||
.info("同步媒体库") | ||
.privacy(CREATOR) | ||
.locality(USER) | ||
.input(0) | ||
.action(ctx -> { | ||
silent.send("开始执行同步任务", ctx.chatId()); | ||
new SyncService().syncFiles("每日更新/"); | ||
silent.send("同步任务执行完成", ctx.chatId()); | ||
}) | ||
.build(); | ||
} | ||
|
||
public Ability syncDir() { | ||
return Ability.builder() | ||
.name("syncDir") | ||
.info("同步指定媒体库路径") | ||
.privacy(CREATOR) | ||
.locality(USER) | ||
.input(0) | ||
.action(ctx -> { | ||
String parameter = ctx.firstArg(); | ||
if (StringUtils.isBlank(parameter)) { | ||
silent.send("请加上路径参数", ctx.chatId()); | ||
return; | ||
} | ||
silent.send("开始执行同步指定路径任务", ctx.chatId()); | ||
new SyncService().syncFiles(parameter); | ||
silent.send("同步指定路径任务执行完成", ctx.chatId()); | ||
}) | ||
.build(); | ||
} | ||
|
||
} |
This file was deleted.
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,48 @@ | ||
package cn.jackding.xiaoyasync.tgbot; | ||
|
||
import cn.jackding.xiaoyasync.config.Config; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.telegram.telegrambots.bots.TelegramLongPollingBot; | ||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; | ||
import org.telegram.telegrambots.meta.api.objects.Update; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; | ||
|
||
/** | ||
* @Author Jack | ||
* @Date 2024/6/4 17:17 | ||
* @Version 1.0.0 | ||
*/ | ||
@Slf4j | ||
public class TgSendMsg extends TelegramLongPollingBot { | ||
|
||
public void sendMsg(String msg) { | ||
if (StringUtils.isBlank(Config.tgUserId) || StringUtils.isBlank(Config.tgToken)) { | ||
return; | ||
} | ||
SendMessage message = new SendMessage(); | ||
message.setChatId(Config.tgUserId); | ||
message.setText(msg); | ||
|
||
try { | ||
execute(message); | ||
} catch (TelegramApiException e) { | ||
log.error("", e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getBotUsername() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String getBotToken() { | ||
return Config.tgToken; | ||
} | ||
|
||
@Override | ||
public void onUpdateReceived(Update update) { | ||
|
||
} | ||
} |