Advertisement
LeRoY_Go

Untitled

Feb 10th, 2022
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.12 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.IO;
  4. using Newtonsoft.Json;
  5. using Telegram.Bot;
  6. using Telegram.Bot.Args;
  7. using Telegram.Bot.Types.ReplyMarkups;
  8.  
  9. namespace BotTelegram
  10. {
  11.     class Program
  12.     {
  13.         private static string token = "2016040925:AAGxwLKV6ZikKCqVHkrT4fQ27c9zQ8ry-QU";
  14.         private const string UrlCoinString = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=space-hamster&order=market_cap_desc&per_page=100&page=1&sparkline=false&price_change_percentage=1h%2C24h%2C7d";
  15.         private static TelegramBotClient client;
  16.         private const string CommandPrefixBuy = "buy";
  17.         private const string CommandPrefixInPrice = "/price";
  18.         private const string CommandPrefixInNFT = "nft";
  19.         private const string CommandPrefixInSwap = "/farm";
  20.         private delegate void Message();
  21.  
  22.         [Obsolete]
  23.         static void Main(string[] args)
  24.         {
  25.             client = new TelegramBotClient(token);
  26.             client.OnMessage += OnMessageHandler;
  27.             client.StartReceiving();
  28.  
  29.         }
  30.  
  31.         [Obsolete]
  32.         private static async void OnMessageHandler(object sender, MessageEventArgs e)
  33.         {
  34.             if (string.IsNullOrWhiteSpace(e.Message.Text)) return;
  35.             string textMessage = e.Message.Text.ToLower();
  36.             bool textBuy = textMessage.Contains(CommandPrefixBuy);
  37.             bool textPrice = textMessage.Contains(CommandPrefixInPrice);
  38.             bool textNFT = textMessage.Contains(CommandPrefixInNFT);
  39.             bool textFarm = textMessage.Contains(CommandPrefixInSwap);
  40.  
  41.             if (textBuy == true)
  42.             {
  43.                 var nameDex = new InlineKeyboardMarkup(new[]{
  44.                   new [] {InlineKeyboardButton.WithUrl(text: "HAMS DEX", url: "https://dex.solhamster.space/#/market/5j6hdwx4eW3QBYZtRjKiUj7aDA1dxDpveSHBznwq7kUv")},
  45.                   new [] {InlineKeyboardButton.WithUrl(text: "DexLab", url: "https://trade.dexlab.space/#/market/5j6hdwx4eW3QBYZtRjKiUj7aDA1dxDpveSHBznwq7kUv")},
  46.                   new [] {InlineKeyboardButton.WithUrl(text: "Aldrin", url: "https://dex.aldrin.com/chart/spot/HAMS_USDC")},
  47.                   new [] {InlineKeyboardButton.WithUrl(text: "LoverDEX", url: "https://samoyedlovers.co/#/market/5j6hdwx4eW3QBYZtRjKiUj7aDA1dxDpveSHBznwq7kUv")},
  48.                   new [] {InlineKeyboardButton.WithUrl(text: "NoGoalDex", url: "https://dex.nogoal.click/#/market/5j6hdwx4eW3QBYZtRjKiUj7aDA1dxDpveSHBznwq7kUv")},
  49.                   new [] {InlineKeyboardButton.WithUrl(text: "Cato Dex", url: "https://catodex.com/#/market/5j6hdwx4eW3QBYZtRjKiUj7aDA1dxDpveSHBznwq7kUv") },
  50.                   new [] {InlineKeyboardButton.WithUrl(text: "Raydium Swap", url: "https://raydium.io/swap/?ammId=z2KxiSejQmNNsyxLFHbrewNLDeGLFZahFNSLYht2FFs")},
  51.                   new [] {InlineKeyboardButton.WithUrl(text: "Jupiter Swap", url: "https://jup.ag/swap/HAMS-USDC") }
  52.                         });
  53.                 await client.SendTextMessageAsync(e.Message.Chat.Id, text: "Buy $HAMS. Click ๐Ÿ‘‡", replyMarkup: nameDex);
  54.             }
  55.             else if (textPrice == true)
  56.             {
  57.                 WebRequest reqGET = WebRequest.Create(UrlCoinString);
  58.                 WebResponse resp = reqGET.GetResponse();
  59.                 Stream stream = resp.GetResponseStream();
  60.                 StreamReader sr = new StreamReader(stream);
  61.                 string s = sr.ReadToEnd();
  62.                 Coin coin = JsonConvert.DeserializeObject<Coin>(s);
  63.  
  64.                 double rfeg = coin.CurrentPrice >= 0 ? coin.CurrentPrice : 0.00;
  65.                 double gergerg = coin.High24h >= 0 ? coin.High24h : 0.00;
  66.                 double frege = coin.Low24h >= 0 ? coin.Low24h : 0.00;
  67.                 double fergerge = coin.PriceChangePercentage1hInCurrency >= 0 ? coin.PriceChangePercentage1hInCurrency : 0.00;
  68.                 double egerge = coin.PriceChangePercentage24hInCurrency >= 0 ? coin.PriceChangePercentage24hInCurrency : 0.00;
  69.                 double egerg = coin.PriceChangePercentage7dInCurrency >= 0 ? coin.PriceChangePercentage7dInCurrency : 0.00;
  70.                 double fwgrgergergre = coin.TotalVolume >= 0 ? coin.TotalVolume : 0.00;
  71.  
  72.                 string coinInfo =
  73.                   $"{coin.Name} - ${coin.Symbol.ToUpper()} \n" +
  74.                   $"๐Ÿ’ฐ Price: ${Math.Round(rfeg, 5)}\n" +
  75.                   $"โš–๏ธ H: ${Math.Round(gergerg, 5)} | L: ${Math.Round(frege, 5)}\n" +
  76.                   $"๐ŸŒš 1h: {Math.Round(fergerge, 2)}%" +
  77.                   $"๐ŸŒš 24h: {Math.Round(egerge, 2)}% \n" +
  78.                   $"๐Ÿ“ˆ 7d: {Math.Round(egerg, 2)}%" +
  79.                   $"๐Ÿ“Š Volume: ${Math.Round(fwgrgergergre, 5)}\n";
  80.  
  81.                 //var coin = await GetFromHttpClient<List<Coin>>();
  82.                 //string d = "๐Ÿ“ˆ 7d: 0.00%";
  83.                 //string h = "๐ŸŒš 1h: 0.00%";
  84.                 //var h24 = coin[0].High24h;
  85.  
  86.                 //if (coin[0].PriceChangePercentage1hInCurrency != null)
  87.                 //{
  88.                 //    h = $"๐ŸŒš 1h: {Math.Round((double)coin[0].PriceChangePercentage1hInCurrency, 2)}%";
  89.                 //}
  90.                 //if (coin[0].PriceChangePercentage7dInCurrency >= 0)
  91.                 //{
  92.                 //    d = $"๐Ÿ“ˆ 7d: {Math.Round((double)coin[0].PriceChangePercentage7dInCurrency, 2)}%";
  93.                 //}
  94.                 //if (h24 == null)
  95.                 //{
  96.                 //    h24 = 0;
  97.                 //}
  98.  
  99.                 //var coinInfo =
  100.                 //  $"{coin[0].Name} - ${coin[0].Symbol.ToUpper()} \n" +
  101.                 //  $"๐Ÿ’ฐ Price: ${Math.Round(coin[0].CurrentPrice, 5)}\n" +
  102.                 //  $"โš–๏ธ H: ${Math.Round((decimal)coin[0].High24h, 5)} | L: ${Math.Round((decimal)coin[0].Low24h, 5)}\n" +
  103.                 //  $"{h}\n" +
  104.                 //  $"๐ŸŒš 24h: {Math.Round((double)coin[0].PriceChangePercentage24hInCurrency, 2)}% \n" +
  105.                 //  $"{d}\n" +
  106.                 //  $"๐Ÿ“Š Volume: ${Math.Round((double)coin[0].TotalVolume, 5)}\n";
  107.  
  108.                 await client.SendTextMessageAsync(e.Message.Chat.Id, text: coinInfo);
  109.             }
  110.             else if (textNFT == true)
  111.             {
  112.                 var nftCollection = new InlineKeyboardMarkup(new[]
  113.                 {
  114.                   new [] {InlineKeyboardButton.WithUrl(text: "Metaplex", url: "https://hams.holaplex.com/#/") },
  115.                   new [] {InlineKeyboardButton.WithUrl(text: "DigitalEyes", url: "https://digitaleyes.market/collections/Space%20Hamster") }
  116.                 });
  117.                 await client.SendTextMessageAsync(e.Message.Chat.Id, text: "Buy $HAMS NFT collection", replyMarkup: nftCollection);
  118.             }
  119.             else if (textFarm == true)
  120.             {
  121.                 var farm = new InlineKeyboardMarkup(new[]
  122.                 {
  123.                   new [] {InlineKeyboardButton.WithUrl(text: "Cropper Farm", url: "https://cropper.finance/farms/?s=Be5mLMaSg1PpBJbK3P6DMAsd9arGi6xeDEApwEVeyHau") }
  124.                 });
  125.                 await client.SendTextMessageAsync(e.Message.Chat.Id, text: "Farm $HAMS. Click ๐Ÿ‘‡", replyMarkup: farm);
  126.             }
  127.             Console.WriteLine(e.Message.Chat.Id);
  128.         }
  129.     }
  130. }
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement