Exemple #1
0
        internal static async Task <bool> CreateInviteLinkAsync(long chatId, TelegramBotAbstract sender)
        {
            string r = null;

            try
            {
                r = await sender.ExportChatInviteLinkAsync(chatId);
            }
            catch
            {
                // ignored
            }

            if (string.IsNullOrEmpty(r))
            {
                return(false);
            }

            const string q1 = "UPDATE Groups SET link = @link, last_update_link = @lul WHERE id = @id";

            SqLite.Execute(q1, new Dictionary <string, object>
            {
                { "@link", r },
                { "@lul", DateTime.Now },
                { "@id", chatId }
            });

            return(true);
        }
        private static void AddMessageType(MessageType type)
        {
            const string q             = "INSERT INTO MessageTypes (name) VALUES (@name)";
            var          keyValuePairs = new Dictionary <string, object> {
                { "@name", type.ToString() }
            };

            SqLite.Execute(q, keyValuePairs);
            Tables.FixIdTable("MessageTypes", "id", "name");
        }
Exemple #3
0
        private static void SalvaNuovoLink(string nuovoLink, long chatId)
        {
            const string q1 = "UPDATE Groups SET link = @link, last_update_link = @lul WHERE id = @id";

            SqLite.Execute(q1, new Dictionary <string, object>
            {
                { "@link", nuovoLink },
                { "@lul", DateTime.Now },
                { "@id", chatId }
            });
        }
        private static async Task SendMessageToSend(DataRow dr)
        {
            var done = await SendMessageFromDataRow(dr);

            if (!done)
            {
                return;
            }

            var q2 = "UPDATE Messages SET has_been_sent = TRUE WHERE id = " + dr["id"];

            SqLite.Execute(q2);
        }
        internal static bool AddMessage(MessageType type, string messageText,
                                        int messageFromIdPerson, int?messageFromIdEntity,
                                        long idChatSentInto, DateTime?sentDate,
                                        bool hasBeenSent, int messageFromIdBot,
                                        int messageIdTgFrom, ChatType type_chat_sent_into,
                                        int?photo_id, int?video_id)
        {
            const string q = "INSERT INTO Messages " +
                             "(id, from_id_person, from_id_entity, type, " +
                             "id_photo, id_video, message_text, id_chat_sent_into, sent_date," +
                             " has_been_sent, from_id_bot, message_id_tg_from, type_chat_sent_into) " +
                             "VALUES " +
                             "(@id, @fip, @fie, @t, @idp, @idv, @mt, @icsi, @sent_date, @hbs, @fib, @mitf, @tcsi);";

            var typeI = GetMessageTypeByName(type);

            if (typeI == null)
            {
                return(false);
            }

            var id = Tables.GetMaxId("Messages", "id");

            id++;

            SqLite.Execute(q, new Dictionary <string, object>
            {
                { "@id", id },
                { "@fip", messageFromIdPerson },
                { "@fie", messageFromIdEntity },
                { "@t", typeI },
                { "@idp", photo_id },
                { "@idv", video_id },
                { "@mt", messageText },
                { "@icsi", idChatSentInto },
                { "@sent_date", sentDate },
                { "@hbs", hasBeenSent },
                { "@fib", messageFromIdBot },
                { "@mitf", messageIdTgFrom },
                { "@tcsi", type_chat_sent_into.ToString() }
            });

            return(true);
        }
Exemple #6
0
        public static void FixIdTable(string tableName, string columnIdName, string uniqueColumn)
        {
            var r4 = GetMaxId(tableName, columnIdName);
            var q2 = "SELECT * FROM " + tableName + " WHERE " + columnIdName + " IS NULL";
            var r5 = SqLite.ExecuteSelect(q2);

            if (r5 == null)
            {
                return;
            }

            foreach (DataRow dr in r5.Rows)
            {
                r4++;

                var valueUnique = dr[uniqueColumn].ToString();
                var q3          = "UPDATE " + tableName + " SET " + columnIdName + "=" + r4 + " WHERE " + uniqueColumn +
                                  "='" + valueUnique + "'";
                SqLite.Execute(q3);
            }
        }
        private static async Task <MessageSendScheduled> SendMessageToSend(DataRow dr,
                                                                           TelegramBotAbstract telegramBotAbstract,
                                                                           bool schedule, TelegramBotAbstract botToReportException)
        {
            bool?has_been_sent            = null;
            Tuple <bool?, int, string> r1 = null;

            try
            {
                r1 = await GetHasBeenSentAsync(dr, telegramBotAbstract);
            }
            catch (Exception e3)
            {
                await NotifyUtil.NotifyOwners(e3, botToReportException);
            }

            if (r1 != null)
            {
                has_been_sent = r1.Item1;
            }

            if (has_been_sent == null)
            {
                return(new MessageSendScheduled(ScheduleMessageSentResult.WE_DONT_KNOW_IF_IT_HAS_BEEN_SENT, null, null,
                                                r1));
            }

            if (has_been_sent.Value)
            {
                return(new MessageSendScheduled(ScheduleMessageSentResult.ALREADY_SENT, null, null, r1));
            }

            DateTime?dt = null;

            try
            {
                dt = (DateTime)dr["sent_date"];
            }
            catch
            {
                ;
            }

            if (schedule && dt == null)
            {
                return(new MessageSendScheduled(ScheduleMessageSentResult.THE_MESSAGE_IS_NOT_SCHEDULED, null, null, r1));
            }

            if (schedule && dt > DateTime.Now)
            {
                return(new MessageSendScheduled(ScheduleMessageSentResult.NOT_THE_RIGHT_TIME, null, null, r1));
            }

            var done = await SendMessageFromDataRow(dr, null, null, false, telegramBotAbstract, 0);

            if (done.IsSuccess() == false)
            {
                return(new MessageSendScheduled(ScheduleMessageSentResult.FAILED_SEND, null, null, r1));
            }

            var q2 = "UPDATE Messages SET has_been_sent = TRUE WHERE id = " + dr["id"];

            SqLite.Execute(q2);

            return(new MessageSendScheduled(ScheduleMessageSentResult.SUCCESS, null, null, r1));
        }