コード例 #1
0
 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 }));
 }
コード例 #2
0
 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 }));
 }
コード例 #3
0
 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 });
 }
コード例 #4
0
 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 }));
 }
コード例 #5
0
ファイル: JetHeraldBot.cs プロジェクト: Jetsparrow/jetherald
 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}"); }
 }
コード例 #6
0
        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));
        }
コード例 #7
0
        Task SendMessageToTelegramChannel(NamespacedId chat, string formatted)
        {
            var id = long.Parse(chat.Id);

            return(TelegramBot.SendTextMessageAsync(id, formatted));
        }
コード例 #8
0
 async Task SendMessageToDiscordChannel(NamespacedId chat, string formatted)
 {
     var id = ulong.Parse(chat.Id);
     await DiscordBot.SendMessageAsync(await DiscordBot.GetChannelAsync(id), formatted);
 }