Skip to content

Commit

Permalink
chats separation
Browse files Browse the repository at this point in the history
PublicChatId -> PublicLibraryChatId, PublicDogChatId
  • Loading branch information
pavel-zhur committed Oct 6, 2024
1 parent 8601a00 commit b0ff281
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public record TelegramOptions : Options.TelegramOptions

public string FilesChatId { get; set; } = null!;

public string PublicChatId { get; set; } = null!;
public string PublicLibraryChatId { get; set; } = null!;

public string PublicDogChatId { get; set; } = null!;

public long PublicChatLongId { get; set; }

public int PublicTopicId { get; set; }

public int AnnouncementsTopicId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public static IServiceCollection AddProcessor(this IServiceCollection services,
.AddSongsDatabase()
.AddTelegram<ScopedAbstractions, SingletonAbstractions>(configuration, o =>
o
.AddCommand<Temp>()

.AddCommand<Likes>()
.AddCommand<FriendsLikes>()
.AddCommand<SongImages>()
Expand All @@ -38,7 +36,6 @@ public static IServiceCollection AddProcessor(this IServiceCollection services,
.AddCommand<Start>()
.AddCommand<ImproveWithParameters>()

.AddCommand<Bowowow>()
.AddCommand<AddSong>()
.AddCommand<MergeSongs>()
.AddCommand<AdditionalKeywords>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<bool> Delete(int messageId)
try
{
await api.DeleteMessageAsync(
_telegramOptions.PublicChatId,
_telegramOptions.PublicLibraryChatId,
messageId);
return true;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ public async Task<int> PublishTextMessage(Markdown markdownV2, InlineKeyboardMar
{
try
{
var messageResult = await api.SendMessageAsync(new(_telegramOptions.PublicChatId, markdownV2.ToString())
var messageResult = await api.SendMessageAsync(new(_telegramOptions.PublicLibraryChatId, markdownV2.ToString())
{
DisableNotification = true,
ParseMode = Constants.MarkdownV2,
Expand Down Expand Up @@ -99,7 +99,7 @@ public async Task<int> PublishFileMessage(string fileId, Markdown markdownV2, In
return await _exponentialBackOff.WithRetry(async () =>
{
var doc = await api.SendDocumentAsync(
_telegramOptions.PublicChatId,
_telegramOptions.PublicLibraryChatId,
fileId,
disableNotification: true,
caption: markdownV2.ToString(),
Expand All @@ -121,7 +121,7 @@ public async Task<bool> UpdateTextMessage(Markdown markdownV2, int messageId, In
{
await api.EditMessageTextAsync<object>(new(markdownV2.ToString())
{
ChatId = _telegramOptions.PublicChatId,
ChatId = _telegramOptions.PublicLibraryChatId,
ParseMode = Constants.MarkdownV2,
MessageId = messageId,
ReplyMarkup = inlineKeyboardMarkup,
Expand Down Expand Up @@ -159,7 +159,7 @@ public async Task<bool> UpdateFileMessage(Markdown markdownV2, int messageId, In
try
{
await api.EditMessageCaptionAsync(
_telegramOptions.PublicChatId,
_telegramOptions.PublicLibraryChatId,
messageId,
caption: markdownV2.ToString(),
parseMode: Constants.MarkdownV2,
Expand All @@ -186,7 +186,7 @@ public async Task Pin(int messageId)
await _exponentialBackOff.WithRetry(async () =>
{
await api.PinChatMessageAsync(
_telegramOptions.PublicChatId,
_telegramOptions.PublicLibraryChatId,
messageId,
disableNotification: true);
});
Expand All @@ -199,7 +199,7 @@ public async Task Unpin(int messageId)
await _exponentialBackOff.WithRetry(async () =>
{
await api.UnpinChatMessageAsync(
_telegramOptions.PublicChatId,
_telegramOptions.PublicLibraryChatId,
messageId: messageId);
});
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AiDialogHandler(

protected override bool CheckRelevant(Update update)
{
if (update.Message?.Chat.Username != _telegramOptions.PublicChatId.Substring(1)) return false;
if (update.Message?.Chat.Username != _telegramOptions.PublicDogChatId.Substring(1)) return false;
if (update.Message.MessageThreadId != _telegramOptions.OwnChatterTopicId) return false;

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override async Task<bool> HandleSync(Update update)
{
if (update.CallbackQuery?.Data == null) return false;

var chatFound = TelegramOptions.PublicChatId.Substring(1) == update.CallbackQuery?.Message?.Chat.Username;
var chatFound = TelegramOptions.PublicLibraryChatId.Substring(1) == update.CallbackQuery?.Message?.Chat.Username;

if (!chatFound) return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ protected override async Task<bool> HandleSync(Update update)

var chatFound =
update.Message.MessageThreadId == _telegramOptions.PublicTopicId || update.Message.MessageThreadId == _telegramOptions.AnnouncementsTopicId
&& _telegramOptions.PublicChatId.Substring(1) == update.Message.Chat.Username;
&& _telegramOptions.PublicLibraryChatId.Substring(1) == update.Message.Chat.Username;

if (!chatFound) return false;

QueueApi(null, async api => await api.DeleteMessageAsync(_telegramOptions.PublicChatId, update.Message.MessageId));
QueueApi(null, async api => await api.DeleteMessageAsync(_telegramOptions.PublicLibraryChatId, update.Message.MessageId));

_logger.LogInformation("Pin removal queued.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public PublicImportHandler(

private bool CheckOurChat(Update update)
{
if (update.Message?.Chat.Username != _telegramOptions.PublicChatId.Substring(1)) return false;
if (update.Message?.Chat.Username != _telegramOptions.PublicLibraryChatId.Substring(1)
&& update.Message?.Chat.Username != _telegramOptions.PublicDogChatId.Substring(1)) return false;
if (update.Message.From == null) return false;

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ public List<List<Type>> GetCommandsGrid()
],


[
typeof(Temp),
typeof(Bowowow)
],


[
typeof(AddSong)
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Microsoft.Extensions.Options;
using OneShelf.Telegram.Helpers;
using OneShelf.Telegram.Model;
using OneShelf.Telegram.Processor.Helpers;
using OneShelf.Telegram.Processor.Model;
using Constants = OneShelf.Telegram.Processor.Helpers.Constants;
using TelegramOptions = OneShelf.Telegram.Processor.Model.TelegramOptions;

Expand All @@ -25,5 +23,5 @@ public string GetManagementUri(int songIndex) =>
public Markdown BuildManagementUrl(string title, int songIndex) => GetManagementUri(songIndex).BuildUrl(title);

private string GenerateMessageLink(int messageId, bool isAnnouncementsTopic = false) =>
$"t.me/{_telegramOptions.PublicChatId.Substring(1)}/{(isAnnouncementsTopic ? _telegramOptions.AnnouncementsTopicId : _telegramOptions.PublicTopicId)}/{messageId}";
$"t.me/{_telegramOptions.PublicLibraryChatId.Substring(1)}/{(isAnnouncementsTopic ? _telegramOptions.AnnouncementsTopicId : _telegramOptions.PublicTopicId)}/{messageId}";
}

0 comments on commit b0ff281

Please sign in to comment.