public async Task <int> RemoveSubscription(string topicName, NamespacedId chat) { using var c = GetConnection(); return(await c.ExecuteAsync( " DELETE tc " + " FROM topic_chat tc" + " JOIN topic t ON tc.TopicId = t.TopicId " + " WHERE t.Name = @topicName AND tc.Chat = @chat;", new { topicName, chat })); }
public async Task <Topic> GetTopicForSub(string token, NamespacedId chat) { using var c = GetConnection(); return(await c.QuerySingleOrDefaultAsync <Topic>( " SELECT t.*, tc.Chat " + " FROM topic t " + " LEFT JOIN topic_chat tc ON t.TopicId = tc.TopicId AND tc.Chat = @chat " + " WHERE ReadToken = @token", new { token, chat })); }
public async Task CreateSubscription(uint topicId, NamespacedId chat) { using var c = GetConnection(); await c.ExecuteAsync( " INSERT INTO topic_chat" + " (Chat, TopicId)" + " VALUES" + " (@chat, @topicId)", new { topicId, chat }); }
public async Task <IEnumerable <Topic> > GetTopicsForChat(NamespacedId chat) { using var c = GetConnection(); return(await c.QueryAsync <Topic>( " SELECT t.*" + " FROM topic_chat ct" + " JOIN topic t on t.TopicId = ct.TopicId" + " WHERE ct.Chat = @chat", new { chat })); }
async Task SendMessageImpl(NamespacedId chat, string formatted) { try { if (chat.Namespace == "telegram") { await SendMessageToTelegramChannel(chat, formatted); } else if (chat.Namespace == "discord") { await SendMessageToDiscordChannel(chat, formatted); } } catch (Exception e) { Log.LogError(e, $"Error while sending message \"{formatted}\" to {chat}"); } }
public async Task <Topic> CreateTopic(NamespacedId user, string name, string descr) { var t = new Topic { Creator = user, Name = name, Description = descr, ReadToken = TokenHelper.GetToken(), WriteToken = TokenHelper.GetToken(), AdminToken = TokenHelper.GetToken() }; using var c = GetConnection(); return(await c.QuerySingleOrDefaultAsync <Topic>( " INSERT INTO herald.topic " + " ( Creator, Name, Description, ReadToken, WriteToken, AdminToken) " + " VALUES " + " (@Creator, @Name, @Description, @ReadToken, @WriteToken, @AdminToken); " + " SELECT * FROM topic WHERE TopicId = LAST_INSERT_ID(); ", t)); }
Task SendMessageToTelegramChannel(NamespacedId chat, string formatted) { var id = long.Parse(chat.Id); return(TelegramBot.SendTextMessageAsync(id, formatted)); }
async Task SendMessageToDiscordChannel(NamespacedId chat, string formatted) { var id = ulong.Parse(chat.Id); await DiscordBot.SendMessageAsync(await DiscordBot.GetChannelAsync(id), formatted); }