當前位置: 首頁>>代碼示例>>C#>>正文


C# Types.Update類代碼示例

本文整理匯總了C#中Telegram.Bot.Types.Update的典型用法代碼示例。如果您正苦於以下問題:C# Update類的具體用法?C# Update怎麽用?C# Update使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Update類屬於Telegram.Bot.Types命名空間,在下文中一共展示了Update類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExecuteAsync

        public override async Task ExecuteAsync(Update update, Dictionary<string, string> parsedMessage)
        {
            if (_responses.Count == 0)
                await Bot.SendTextMessageAsync(update.Message.Chat.Id, "Зато мы делаем ракеты", false, false, update.Message.MessageId);

            if (!parsedMessage.ContainsKey("message") || string.IsNullOrEmpty(parsedMessage["message"]))
                return;

            var ind = _rng.Next(0, _maxRadnomValue);
            string answer = "";
            for (var i = _weights.Count - 1; i >= 0; i--)
            {
                if (ind >= _weights[i])
                {
                    answer = _responses[i];
                    break;
                }
            }
            // Border case, if the value is between 0 and first answer's weight, no value will be selected
            if (string.IsNullOrEmpty(answer))
            {
                answer = _responses[0];
            }
            await Bot.SendTextMessageAsync(update.Message.Chat.Id, answer, false, false, update.Message.MessageId);
        }
開發者ID:Angelore,項目名稱:dwellerbot,代碼行數:25,代碼來源:AskStasonCommand.cs

示例2: ExecuteAsync

        public override async Task ExecuteAsync(Update update, Dictionary<string, string> parsedMessage)
        {
            // Restore default value
            _location = "Minsk,by";

            // If arguments are supplied, try to insert them into query
            if (parsedMessage.ContainsKey("message"))
            {
                var args = parsedMessage["message"].Split(',');
                if (args.Length >= 2)
                {
                    _location = args[0] + "," + args[1];
                }
            }

            var responseStream = new StreamReader(await GetWeather());
            var weatherContainer = JsonConvert.DeserializeObject<WeatherContainer>(responseStream.ReadToEnd());
            if (weatherContainer.cod == 404)
            {
                await Bot.SendTextMessageAsync(update.Message.Chat.Id, "Invalid arguments.", false, false, update.Message.MessageId);
                return;
            }

            var sb = new StringBuilder();
            sb.Append("Погода в " + weatherContainer.name + ", " + weatherContainer.sys.country);
            sb.AppendLine(" на " + weatherContainer.dt.UnixTimeStampToDateTime().ToLocalTime().ToShortDateString());
            sb.AppendLine();
            sb.AppendLine("Температура: " + weatherContainer.main.temp + " *C, " + weatherContainer.weather[0].description);
            sb.AppendLine("Влажность: " + weatherContainer.main.humidity + "%");
            sb.AppendLine("Ветер: " + weatherContainer.wind.speed + " м/с");
            await Bot.SendTextMessageAsync(update.Message.Chat.Id, sb.ToString(), false, false, update.Message.MessageId);
        }
開發者ID:Angelore,項目名稱:dwellerbot,代碼行數:32,代碼來源:WeatherCommand.cs

示例3: Run

        public async Task Run()
        {
            var me = await _bot.GetMe();
            
            Log.Logger.Information("{0} is online and fully functional." + Environment.NewLine, me.Username);

            while (IsOnline)
            {
                Update[] updates = new Update[0];
                try
                {
                    updates = await _bot.GetUpdates(Offset);
                }
                catch (Exception ex)
                {
                    Log.Logger.Error("An error has occured while receiving updates. Error message: {0}", ex.Message);
                    ErrorCount++;
                }

                foreach (var update in updates)
                {
                    CommandService.HandleUpdate(update);

                    Offset = update.Id + 1;
                }

                await Task.Delay(1000);
            }
        }
開發者ID:forcewake,項目名稱:dwellerbot,代碼行數:29,代碼來源:DwellerBot.cs

示例4: ExecuteAsync

        public override async Task ExecuteAsync(Update update, Dictionary<string, string> parsedMessage)
        {
            var response = await GetHtml();
            string responseString;
            using (var tr = new StreamReader(response))
            {
                responseString = tr.ReadToEnd();
            }

            var startIndex = responseString.IndexOf("+=") + 2;
            var endIndex = responseString.IndexOf(";\ndocument");
            var tempStr = responseString.Substring(startIndex, endIndex - startIndex);
            var partsList = tempStr.Split('+').Select(x => x.Trim()).ToList();
            tempStr = "";
            // remove ' symbols
            partsList.ForEach(x => tempStr += x.Substring(1, x.Length - 2));

            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(tempStr);
            var quote = document.GetElementbyId(QuoteTagId);
            var rating = document.GetElementbyId(RatingTagId);
            
            var result = rating.InnerText + Environment.NewLine + quote.InnerHtml.Replace(QuoteLineBreak, Environment.NewLine);
            
            await Bot.SendTextMessageAsync(update.Message.Chat.Id, HttpUtility.HtmlDecode(result), false, false, update.Message.MessageId);
        }
開發者ID:Angelore,項目名稱:dwellerbot,代碼行數:26,代碼來源:BashimCommand.cs

示例5: GetLang

        public static void GetLang(Update update, string[] args)
        {
            var glangs = Directory.GetFiles(Bot.LanguageDirectory)
                                                        .Select(x => XDocument.Load(x)
                                                                    .Descendants("language")
                                                                    .First()
                                                                    .Attribute("name")
                                                                    .Value
                                                        ).ToList();
            glangs.Insert(0, "All");

            var gbuttons = glangs.Select(x => new InlineKeyboardButton(x, $"getlang|{update.Message.Chat.Id}|{x}")).ToList();
            var baseMenu = new List<InlineKeyboardButton[]>();
            for (var i = 0; i < gbuttons.Count; i++)
            {
                if (gbuttons.Count - 1 == i)
                {
                    baseMenu.Add(new[] { gbuttons[i] });
                }
                else
                    baseMenu.Add(new[] { gbuttons[i], gbuttons[i + 1] });
                i++;
            }

            var gmenu = new InlineKeyboardMarkup(baseMenu.ToArray());
            Bot.Api.SendTextMessage(update.Message.Chat.Id, "Get which language file?", replyToMessageId: update.Message.MessageId, replyMarkup: gmenu);
        }
開發者ID:RainRat,項目名稱:Werewolf,代碼行數:27,代碼來源:GeneralCommands.cs

示例6: ExecuteAsync

        public override async Task ExecuteAsync(Update update, Dictionary<string, string> parsedMessage)
        {
            var rtdRegex = new Regex(@"^(\d*)d(4|6|20|100)");

            if (parsedMessage.ContainsKey("message"))
            {
                if (rtdRegex.IsMatch(parsedMessage["message"]))
                {
                    var rtdMatch = rtdRegex.Match(parsedMessage["message"]);
                    var numberOfDice = rtdMatch.Groups[1].Value == "" ? 1 : int.Parse(rtdMatch.Groups[1].Value);
                    var diceEdges = int.Parse(rtdMatch.Groups[2].Value);
                    if ((numberOfDice > 0 && numberOfDice <= 6) &&
                        (diceEdges == 4 || diceEdges == 6 || diceEdges == 20 || diceEdges == 100))
                    {
                        var sb = new StringBuilder();
                        sb.AppendLine(update.Message.From.FirstName + " rolled the dice.");
                        for (var index = 0; index < numberOfDice; index++)
                        {
                            sb.AppendLine("Dice " + (index + 1) + ": " + (_rng.Next(diceEdges) + 1));
                        }
                        await Bot.SendTextMessageAsync(update.Message.Chat.Id, sb.ToString(), false, false, update.Message.MessageId);
                        return;
                    }
                }
            }

            await Bot.SendTextMessageAsync(update.Message.Chat.Id, "Format: [number(?1-6)]d[number(4|6|20|100)].", false, false, update.Message.MessageId);
        }
開發者ID:Angelore,項目名稱:dwellerbot,代碼行數:28,代碼來源:RtdCommand.cs

示例7: Post

        public async Task<IHttpActionResult> Post(Update update)
        {
            var message = update.Message;

            Console.WriteLine("Received Message from {0}", message.Chat.Id);

            if (message.Type == MessageType.TextMessage)
            {
                // Echo each Message
                await Bot.Api.SendTextMessage(message.Chat.Id, message.Text);
            }
            else if (message.Type == MessageType.PhotoMessage)
            {
                // Download Photo
                var file = await Bot.Api.GetFile(message.Photo.LastOrDefault()?.FileId);

                var filename = file.FileId + "." + file.FilePath.Split('.').Last();

                using (var saveImageStream = File.Open(filename, FileMode.Create))
                {
                    await file.FileStream.CopyToAsync(saveImageStream);
                }

                await Bot.Api.SendTextMessage(message.Chat.Id, "Thx for the Pics");
            }

            return Ok();
        }
開發者ID:johnvan7,項目名稱:telegram.bot,代碼行數:28,代碼來源:Program.cs

示例8: Flee

        public static void Flee(Update update, string[] args)
        {
            var id = update.Message.Chat.Id;
            //check nodes to see if player is in a game
            var node = GetPlayerNode(update.Message.From.Id);
            var game = GetGroupNodeAndGame(update.Message.Chat.Id);
            if (game != null || node != null)
            {
                //try grabbing the game again...
                if (node != null)
                    game =
                        node.Games.FirstOrDefault(
                            x => x.Users.Contains(update.Message.From.Id));
                if (game?.Users.Contains(update.Message.From.Id) ?? false)
                {
                    game?.RemovePlayer(update);

                    return;
                }
                if (node != null)
                {
                    //there is a game, but this player is not in it
                    Send(GetLocaleString("NotPlaying", GetLanguage(id)), id);
                }
            }
            else
            {
                Send(GetLocaleString("NoGame", GetLanguage(id)), id);
            }
        }
開發者ID:CloneMMDDCVII,項目名稱:Werewolf,代碼行數:30,代碼來源:GameCommands.cs

示例9: Execute

 public async void Execute(Update update)
 {
     var city = GetCityFromMessage(update.Message.Text);
     var weather = _weatherService.GetWeatherForCity(city);
     var message = WeatherMessageBuilder.Build(weather.Name, weather.Description, weather.Temperature);
     await _bot.SendTextMessage(update.Message.Chat.Id, message);
     Console.WriteLine("Echo Message: {0}", message);
 }
開發者ID:olegpopok,項目名稱:BecomeSolid,代碼行數:8,代碼來源:WeatherCommand.cs

示例10: ExecuteAsync

 public override async Task ExecuteAsync(Update update, Dictionary<string, string> parsedMessage)
 {
     var sb = new StringBuilder();
     sb.AppendLine("Launch time: " + _dwellerBot.LaunchTime.ToUniversalTime());
     sb.AppendLine("Commands processed: " + _dwellerBot.CommandsProcessed);
     sb.AppendLine("Errors: " + _dwellerBot.ErrorCount);
     await Bot.SendTextMessage(update.Message.Chat.Id, sb.ToString(), false, update.Message.MessageId);
 }
開發者ID:forcewake,項目名稱:dwellerbot,代碼行數:8,代碼來源:DebugCommand.cs

示例11: TratarUpdate

 private static void TratarUpdate(Update update, ref int offset)
 {
     var message = update.Message;
     WriteLine($"Mensagem recebida!");
     WriteLine($"Id: {message.MessageId} | Message type: {message.Type} | Message: {message.Text} | from: {message.Chat.Username}");
     api.SendTextMessage(message.Chat.Id, $"Olá {message.Chat.FirstName}, recebi sua mensagem X)");
     offset = update.Id + 1;
 }
開發者ID:JoelRamosM,項目名稱:BotRegPonto,代碼行數:8,代碼來源:Program.cs

示例12: AddPlayer

 public void AddPlayer(Update update)
 {
     var n = Bot.Nodes.FirstOrDefault(x => x.ClientId == NodeId);
     if (n == null) return;
     var g = n.Games.FirstOrDefault(x => x.GroupId == update.Message.Chat.Id);
     g?.Users.Add(update.Message.From.Id);
     var json = JsonConvert.SerializeObject(new PlayerJoinInfo { User = update.Message.From, GroupId = update.Message.Chat.Id });
     n.Broadcast(json);
 }
開發者ID:RainRat,項目名稱:Werewolf,代碼行數:9,代碼來源:GameInfo.cs

示例13: GetStats

 public static void GetStats(Update update, string[] args)
 {
     var reply = $"[Global Stats](werewolf.parawuff.com/Stats)\n";
     if (update.Message.Chat.Type != ChatType.Private)
         reply += $"[Group Stats](werewolf.parawuff.com/Stats/Group/{update.Message.Chat.Id}) ({update.Message.Chat.Title})\n";
     reply += $"[Player Stats](werewolf.parawuff.com/Stats/Player/{update.Message.From.Id}) ({update.Message.From.FirstName})";
     Bot.Api.SendTextMessage(update.Message.Chat.Id, reply, parseMode: ParseMode.Markdown,
         disableWebPagePreview: true);
 }
開發者ID:RainRat,項目名稱:Werewolf,代碼行數:9,代碼來源:GeneralCommands.cs

示例14: IsAppropriate

 public bool IsAppropriate(Update update)
 {
     if (update.Message.Type == MessageType.TextMessage)
     {
         var inputMessage = update.Message.Text;
         return inputMessage.StartsWith("/weather");
     }
     return false;
 }
開發者ID:eugeni96,項目名稱:SOLID,代碼行數:9,代碼來源:WeatherCommand.cs

示例15: RemovePlayer

        public void RemovePlayer(Update update)
        {
            var n = Bot.Nodes.FirstOrDefault(x => x.ClientId == NodeId);
            if (n == null) return;

            Users.Remove(update.Message.From.Id);
            var json = JsonConvert.SerializeObject(new PlayerFleeInfo { User = update.Message.From, GroupId = update.Message.Chat.Id });
            n.Broadcast(json);
        }
開發者ID:RainRat,項目名稱:Werewolf,代碼行數:9,代碼來源:GameInfo.cs


注:本文中的Telegram.Bot.Types.Update類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。