Skip to content
Open
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
1 change: 1 addition & 0 deletions Werewolf for Telegram/Database/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public Group()
public int Id { get; set; }
public string Name { get; set; }
public long GroupId { get; set; }
public Nullable<int> GroupTopicId { get; set; }
public Nullable<bool> Preferred { get; set; }
public string Language { get; set; }
public Nullable<bool> DisableNotification { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion Werewolf for Telegram/Database/WerewolfModel.edmx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="Name" Type="nvarchar(max)" Nullable="false" />
<Property Name="GroupId" Type="bigint" Nullable="false" />
<Property Name="GroupTopicId" Type="int" />
<Property Name="Preferred" Type="bit" />
<Property Name="Language" Type="nvarchar(max)" />
<Property Name="DisableNotification" Type="bit" />
Expand Down Expand Up @@ -884,6 +885,7 @@ warning 6002: The table/view 'werewolf.dbo.v_IdleKill24HoursMain' does not have
<Property Name="Id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="Name" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" Nullable="false" />
<Property Name="GroupId" Type="Int64" Nullable="false" />
<Property Name="GroupTopicId" Type="Int32" />
<Property Name="Preferred" Type="Boolean" />
<Property Name="Language" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
<Property Name="DisableNotification" Type="Boolean" />
Expand Down Expand Up @@ -1664,6 +1666,7 @@ warning 6002: The table/view 'werewolf.dbo.v_IdleKill24HoursMain' does not have
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
<ScalarProperty Name="GroupId" ColumnName="GroupId" />
<ScalarProperty Name="GroupTopicId" ColumnName="GroupTopicId" />
<ScalarProperty Name="Preferred" ColumnName="Preferred" />
<ScalarProperty Name="Language" ColumnName="Language" />
<ScalarProperty Name="DisableNotification" ColumnName="DisableNotification" />
Expand Down Expand Up @@ -2176,4 +2179,4 @@ warning 6002: The table/view 'werewolf.dbo.v_IdleKill24HoursMain' does not have
<!-- Diagram content (shape and connector positions) -->
<Diagrams></Diagrams>
</Designer>
</edmx:Edmx>
</edmx:Edmx>
14 changes: 14 additions & 0 deletions Werewolf for Telegram/Languages/English.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2269,5 +2269,19 @@
<string key="ArsonistNotFrozen">
<value>As you were preparing your kerosene and lighter, a gust of wind blew in from the doorway, causing you to freeze 🐺☃️. The snow wolf was here! But if you know one thing, it is that ice can be beaten by fire. Standing right next to one of the numerous candles in your house, you feel how its heat thaws you, allowing you to move. Nothing can stop your fire! 🔥</value>
</string>

<string key="SetTopicCmdNotInGeneral">
<value>❌ You must run this command inside a topic/thread (not the general topic).</value>
</string>
<string key="SetTopicSuccess">
<value>✅ Group topic has been set successfully.</value>
</string>
<string key="UnsetTopicSuccess">
<value>🗑️ Group topic has been unset.</value>
</string>

<string key="MustRunInConfiguredTopic">
<value>This command can only be used in the configured topic/thread. (Topic id : {0})</value>
</string>
Comment on lines +2272 to +2285
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, forget to format it to proper indentation


</strings>
5 changes: 5 additions & 0 deletions Werewolf for Telegram/Werewolf Control/Attributes/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ public class Command : Attribute
/// Can this command be run by anonymous admins in groups
/// </summary>
public bool AllowAnonymousAdmins { get; set; } = false;

/// <summary>
/// Allow commands to be run outside configured topic in group.
/// </summary>
public bool AllowOutsideConfiguredTopic { get; set; } = false;
}
}
56 changes: 55 additions & 1 deletion Werewolf for Telegram/Werewolf Control/Commands/AdminCommands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Database;
using Database;
using Newtonsoft.Json;
using System;
using System.Collections;
Expand All @@ -23,6 +23,60 @@ namespace Werewolf_Control
{
public static partial class Commands
{
[Attributes.Command(Trigger = "settopic", GroupAdminOnly = true, InGroupOnly = true)]
public static void SetTopic(Update update, string[] args)
{
long chatId = update.Message.Chat.Id;
int? topicId = update.Message.MessageThreadId;

// TODO: allow general topic? some group may use general topic for game.
if (topicId == null)
{
Bot.Send(GetLocaleString("SetTopicCmdNotInGeneral",GetLanguage(chatId)).ToBold(), chatId, messageThreadId: 0);
return;
}

using (var db = new WWContext())
{
var group = db.Groups.FirstOrDefault(g => g.GroupId == chatId);
if (group == null)
{
group = MakeDefaultGroup(chatId, update.Message.Chat.Title, "settopic_cmd");
db.Groups.Add(group);
}

group.GroupTopicId = topicId;
Helpers.Bot.ChatTopicIdCache[chatId] = topicId;
db.SaveChanges();
}

Bot.Send(GetLocaleString("SetTopicSuccess",GetLanguage(chatId)).ToBold(), chatId, messageThreadId: topicId.Value);
}

[Attributes.Command(Trigger = "remtopic", GroupAdminOnly = true, InGroupOnly = true)]
public static void RemoveTopic(Update update, string[] args)
{
long chatId = update.Message.Chat.Id;
int? topicId = update.Message.MessageThreadId;

using (var db = new WWContext())
{
var group = db.Groups.FirstOrDefault(g => g.GroupId == chatId);
if (group == null)
{
group = MakeDefaultGroup(chatId, update.Message.Chat.Title, "remtopic_cmd");
db.Groups.Add(group);
}

group.GroupTopicId = null;
Helpers.Bot.ChatTopicIdCache[chatId] = null;
db.SaveChanges();
}

Bot.Send(GetLocaleString("SetTopicSuccess", GetLanguage(chatId)).ToBold(), chatId, messageThreadId: topicId ?? 0);
}


[Attributes.Command(Trigger = "smite", GroupAdminOnly = true, Blockable = true, InGroupOnly = true, AllowAnonymousAdmins = true)]
public static void Smite(Update u, string[] args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public static void Extend(Update update, string[] args)
}
}

[Command(Trigger = "stopwaiting", Blockable = true)]
// allowing outside topic, as it doesn't response into topic command was ran. dm user that their next game notification is turned off
[Command(Trigger = "stopwaiting", Blockable = true, AllowOutsideConfiguredTopic = true)]
public static void StopWaiting(Update update, string[] args)
{
long groupid = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public static void SetLang(Update update, string[] args)
var curLangFileName = GetLanguage(update.Message.From.Id);
var curLang = langs.First(x => x.FileName == curLangFileName);
Bot.Api.SendTextMessageAsync(chatId: update.Message.From.Id, text: GetLocaleString("WhatLang", curLangFileName, curLang.Base),
replyMarkup: menu);
replyMarkup: menu, messageThreadId: update.Message.MessageThreadId);
if (update.Message.Chat.Type != ChatType.Private)
Send(GetLocaleString("SentPrivate", GetLanguage(update.Message.From.Id)), update.Message.Chat.Id);
Send(GetLocaleString("SentPrivate", GetLanguage(update.Message.From.Id)), update.Message.Chat.Id, messageThreadId: update.Message.MessageThreadId);
}

[Command(Trigger = "start")]
Expand Down Expand Up @@ -581,7 +581,7 @@ public static void MyIdles(Update update, string[] args)

try
{
var result = Bot.Api.SendTextMessageAsync(chatId: update.Message.From.Id, text: reply).Result;
var result = Bot.Api.SendTextMessageAsync(chatId: update.Message.From.Id, text: reply, messageThreadId: update.Message.MessageThreadId).Result;
if (update.Message.Chat.Type != ChatType.Private)
Send(GetLocaleString("SentPrivate", GetLanguage(update.Message.From.Id)), update.Message.Chat.Id);
}
Expand Down
22 changes: 11 additions & 11 deletions Werewolf for Telegram/Werewolf Control/Commands/GifCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void Donate(Update u, string[] args)
{
// Donations disabled as of 2024-06-08
var link = $"<a href=\"https://t.me/greywolfdev/1318\">currently disabled</a>";
Bot.Api.SendTextMessageAsync(chatId: u.Message.Chat.Id, text: $"Donations are {link}, sorry!", parseMode: ParseMode.Html, disableWebPagePreview: true).Wait();
Bot.Api.SendTextMessageAsync(chatId: u.Message.Chat.Id, text: $"Donations are {link}, sorry!", parseMode: ParseMode.Html, disableWebPagePreview: true, messageThreadId: u.Message.MessageThreadId).Wait();
return;

//Bot.Api.SendTextMessageAsync(u.Message.Chat.Id,
Expand Down Expand Up @@ -106,7 +106,7 @@ public static void SetCustomGifs(Update u, string[] args)
"\n\n" +
"PLEASE NOTE: Changing any gifs will automatically remove the approval for your pack, and an admin will need to approve it again\n" +
"Let's begin! Select the situation you want to set a gif for",
replyMarkup: GetGifMenu(data));
replyMarkup: GetGifMenu(data), messageThreadId: u.Message.MessageThreadId);

var msg = "Current Approval Status:\n";
switch (data.Approved)
Expand All @@ -123,7 +123,7 @@ public static void SetCustomGifs(Update u, string[] args)
msg += "Disapproved By " + dby.Name + " for: " + data.DenyReason;
break;
}
Bot.Send(msg, u.Message.From.Id);
Bot.Send(msg, u.Message.From.Id, messageThreadId: u.Message.MessageThreadId);
}

}
Expand Down Expand Up @@ -304,7 +304,7 @@ public static void RequestGif(CallbackQuery q)
Bot.Api.SendTextMessageAsync(chatId: q.From.Id,
text: q.Data.Split('|')[1] + "\nOk, send me the GIF you want to use for this situation, as a reply\n" +
"#" + choice,
replyMarkup: new ForceReplyMarkup());
replyMarkup: new ForceReplyMarkup(), messageThreadId: q.Message.MessageThreadId);
}

public static void AddGif(Message m)
Expand Down Expand Up @@ -337,14 +337,14 @@ public static void AddGif(Message m)
"users are unable to view them, we require you to use telegram's " +
"[new GIFs in .mp4 format](https://telegram.org/blog/gif-revolution). " +
"To fix this, try reuploading the GIF, your telegram app should then render it as .mp4. " +
"Please send me the GIF you want to use for this situation, as a reply\n#" + gifchoice, replyMarkup: new ForceReplyMarkup(), parseMode: ParseMode.Markdown);
"Please send me the GIF you want to use for this situation, as a reply\n#" + gifchoice, replyMarkup: new ForceReplyMarkup(), parseMode: ParseMode.Markdown, messageThreadId: m.MessageThreadId);
return;
}
if (m.Animation.FileSize >= 1048576) // Maximum size is 1 MB
{
Bot.Api.SendTextMessageAsync(chatId: m.From.Id, text: "This GIF is too large, the maximum allowed size is 1MB.\n\n" +
"Please send me the GIF you want to use for this situation, as a reply\n#" + gifchoice,
replyMarkup: new ForceReplyMarkup());
replyMarkup: new ForceReplyMarkup(), messageThreadId: m.MessageThreadId);
return;
}

Expand Down Expand Up @@ -431,7 +431,7 @@ public static void GetXsollaLink(CallbackQuery q = null, Message m = null)
{
// Donations disabled as of 2024-06-08
var link = $"<a href=\"https://t.me/greywolfdev/1318\">currently disabled</a>";
Bot.Api.SendTextMessageAsync(chatId: (q?.Message ?? m).Chat.Id, text: $"Donations are {link}, sorry!", parseMode: ParseMode.Html, disableWebPagePreview: true).Wait();
Bot.Api.SendTextMessageAsync(chatId: (q?.Message ?? m).Chat.Id, text: $"Donations are {link}, sorry!", parseMode: ParseMode.Html, disableWebPagePreview: true, messageThreadId: (q?.Message ?? m).MessageThreadId).Wait();
return;

var from = q?.From ?? m?.From;
Expand Down Expand Up @@ -465,13 +465,13 @@ public static void GetDonationInfo(CallbackQuery q = null, Message m = null)
{
// Donations disabled as of 2024-06-08
var link = $"<a href=\"https://t.me/greywolfdev/1318\">currently disabled</a>";
Bot.Api.SendTextMessageAsync(chatId: q?.From.Id ?? m.From.Id, text: $"Donations are {link}, sorry!", parseMode: ParseMode.Html, disableWebPagePreview: true).Wait();
Bot.Api.SendTextMessageAsync(chatId: q?.From.Id ?? m.From.Id, text: $"Donations are {link}, sorry!", parseMode: ParseMode.Html, disableWebPagePreview: true, messageThreadId: q.Message.MessageThreadId).Wait();
return;

var menu = new Menu();
Bot.Api.SendTextMessageAsync(chatId: q?.From.Id ?? m.From.Id,
text: "How much would you like to donate? Please enter a whole number, in US Dollars (USD), in reply to this message",
replyMarkup: new ForceReplyMarkup());
replyMarkup: new ForceReplyMarkup(), messageThreadId: (q?.Message ?? m).MessageThreadId);
}

public static void ValidateDonationAmount(Message m)
Expand All @@ -488,14 +488,14 @@ public static void ValidateDonationAmount(Message m)
var api = RegHelper.GetRegValue("MainStripeProdAPI");
#endif
Bot.Api.SendInvoiceAsync(chatId: m.From.Id, title: "Werewolf Donation", description: "Make a donation to Werewolf to help keep us online", payload: "somepayloadtest", providerToken: api,
currency: "USD", prices: new[] { new LabeledPrice("Donation", amt * 100) }, startParameter: "donatetg").Wait();
currency: "USD", prices: new[] { new LabeledPrice("Donation", amt * 100) }, startParameter: "donatetg", messageThreadId: m.MessageThreadId).Wait();
}
else
{
Bot.Api.SendTextMessageAsync(chatId: m.From.Id,
text: "Invalid input.\n" +
"How much would you like to donate? Please enter a whole number, in US Dollars (USD), in reply to this message",
replyMarkup: new ForceReplyMarkup());
replyMarkup: new ForceReplyMarkup(), messageThreadId: m.MessageThreadId);
}

}
Expand Down
4 changes: 2 additions & 2 deletions Werewolf for Telegram/Werewolf Control/Commands/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ private static void StartGame(GameMode gameMode, Update update)
}
}

internal static Task<Message> Send(string message, long id, bool clearKeyboard = false, InlineKeyboardMarkup customMenu = null)
internal static Task<Message> Send(string message, long id, bool clearKeyboard = false, InlineKeyboardMarkup customMenu = null, Nullable<int> messageThreadId = null)
{
return Bot.Send(message, id, clearKeyboard, customMenu);
return Bot.Send(message, id, clearKeyboard, customMenu, messageThreadId: messageThreadId);
}


Expand Down
Loading