Skip to content

Commit b58eaa9

Browse files
committed
Add command to enable/disable public/mod commmands
Adds a command to enable/disable public/mod commands from chat. This was not yet implemented in v2. Should work exactly the same as in v1.
1 parent 76fb300 commit b58eaa9

File tree

8 files changed

+81
-2
lines changed

8 files changed

+81
-2
lines changed

locales/de.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ de:
4444
sceneSwitch:
4545
switch: Szene erfolgreich auf "%{scene}" gewechselt
4646
handleCommands:
47+
public: Öffentliche Befehle %{condition}
48+
mod: Mod Befehle %{condition}
4749
notify: Automatische Wechsel Benachrichtigung %{condition}
4850
autostop: Stream automatisch gestoppt %{condition}
4951
enabled: ist aktiviert

locales/dk.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ dk:
4444
sceneSwitch:
4545
switch: Scene skiftet til "%{scene}"
4646
handleCommands:
47+
public: Offentlige kommandoer %{condition}
48+
mod: Mod kommandoer %{condition}
4749
notify: Automatiske sceneskift notifikationer %{condition}
4850
autostop: Auto stop stream %{condition}
4951
enabled: slået til

locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ en:
4444
sceneSwitch:
4545
switch: Scene switched to "%{scene}"
4646
handleCommands:
47+
public: Public commands %{condition}
48+
mod: Mod commands %{condition}
4749
notify: Auto switch notification %{condition}
4850
autostop: Auto stop stream %{condition}
4951
enabled: is enabled

locales/ru.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ ru:
4444
sceneSwitch:
4545
switch: Сцена переключена на "%{scene}"
4646
handleCommands:
47+
public: Публичные команды %{condition}
48+
mod: Команды модераторов %{condition}
4749
notify: Автоуведомления %{condition}
4850
autostop: Автоостановка %{condition}
4951
enabled: включены

locales/tr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ tr:
4444
sceneSwitch:
4545
switch: Sahne değiştirildi "%{scene}"
4646
handleCommands:
47+
public: Genel komutlar %{condition}
48+
mod: Mod komutları %{condition}
4749
notify: Otomatik geçiş bildirimi %{condition}
4850
autostop: Yayını otomatik durdur %{condition}
4951
enabled: etkin

locales/zh_tw.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ zh_tw:
4646
sceneSwitch:
4747
switch: 場景切換到 "%{scene}"
4848
handleCommands:
49+
public: 公用指令 %{condition}
50+
mod: Mod 指令 %{condition}
4951
notify: 自動切換通知 %{condition}
5052
autostop: 自動停止直播 %{condition}
5153
enabled: 開啟

src/chat/chat_handler.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ impl DispatchCommand {
491491
chat::Command::EndingScene => self.ending_scene().await,
492492
chat::Command::LiveScene => self.live_scene().await,
493493
chat::Command::Obsinfo => {}
494-
chat::Command::Mod => {}
495-
chat::Command::Public => {}
494+
chat::Command::Mod => self.enable_mod(params.next()).await,
495+
chat::Command::Public => self.enable_public(params.next()).await,
496496
chat::Command::Sourceinfo => self.source_info(params.next()).await,
497497
chat::Command::Unknown(_) => {}
498498
};
@@ -1063,6 +1063,41 @@ impl DispatchCommand {
10631063
self.send(msg.join(" - ")).await;
10641064
}
10651065

1066+
async fn enable_mod(&self, enabled: Option<&str>) {
1067+
if let Some(enabled) = enabled {
1068+
if let Ok(b) = enabled_to_bool(enabled) {
1069+
self.user.set_enable_mod(b).await.unwrap();
1070+
self.save_config().await;
1071+
}
1072+
}
1073+
1074+
let msg = t!(
1075+
"handleCommands.mod",
1076+
locale = &self.lang,
1077+
condition = &condition_to_text(self.user.get_enable_mod().await.unwrap(), &self.lang)
1078+
);
1079+
1080+
self.send(msg).await;
1081+
}
1082+
1083+
async fn enable_public(&self, enabled: Option<&str>) {
1084+
if let Some(enabled) = enabled {
1085+
if let Ok(b) = enabled_to_bool(enabled) {
1086+
self.user.set_enable_public(b).await.unwrap();
1087+
self.save_config().await;
1088+
}
1089+
}
1090+
1091+
let msg = t!(
1092+
"handleCommands.public",
1093+
locale = &self.lang,
1094+
condition =
1095+
&condition_to_text(self.user.get_enable_public().await.unwrap(), &self.lang)
1096+
);
1097+
1098+
self.send(msg).await;
1099+
}
1100+
10661101
async fn send(&self, message: String) {
10671102
self.chat_sender
10681103
.send_message(self.chat_message.channel.to_owned(), message)

src/noalbs.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,38 @@ impl Noalbs {
239239
toggle
240240
}
241241

242+
pub async fn get_enable_mod(&self) -> Result<bool, error::Error> {
243+
let state = &self.state.read().await;
244+
let chat = &state.config.chat.as_ref().ok_or(error::Error::NoChat)?;
245+
246+
Ok(chat.enable_mod_commands)
247+
}
248+
249+
pub async fn set_enable_mod(&self, enabled: bool) -> Result<(), error::Error> {
250+
let mut state = self.state.write().await;
251+
let chat = state.config.chat.as_mut().ok_or(error::Error::NoChat)?;
252+
253+
chat.enable_mod_commands = enabled;
254+
255+
Ok(())
256+
}
257+
258+
pub async fn get_enable_public(&self) -> Result<bool, error::Error> {
259+
let state = &self.state.read().await;
260+
let chat = &state.config.chat.as_ref().ok_or(error::Error::NoChat)?;
261+
262+
Ok(chat.enable_public_commands)
263+
}
264+
265+
pub async fn set_enable_public(&self, enabled: bool) -> Result<(), error::Error> {
266+
let mut state = self.state.write().await;
267+
let chat = state.config.chat.as_mut().ok_or(error::Error::NoChat)?;
268+
269+
chat.enable_public_commands = enabled;
270+
271+
Ok(())
272+
}
273+
242274
pub async fn get_notify(&self) -> bool {
243275
let state = self.state.read().await;
244276

0 commit comments

Comments
 (0)