Skip to content

Commit

Permalink
ahora es más simple hacer más
Browse files Browse the repository at this point in the history
  • Loading branch information
tetradog committed Jul 11, 2021
1 parent 95b695a commit d2d642d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 88 deletions.
2 changes: 1 addition & 1 deletion CheckFenix.TelegramBot/CheckFenix.TelegramBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Telegram.Bot" Version="16.0.0" />
<PackageReference Include="Gabriel.Cat.S.Check" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
108 changes: 21 additions & 87 deletions CheckFenix.TelegramBot/Program.cs
Original file line number Diff line number Diff line change
@@ -1,108 +1,42 @@
using System;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Exceptions;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;
using CheckFenix.Core;
using System.Linq;
using Gabriel.Cat.S.Check;

namespace CheckFenix.TelegramBot
{
class Program
public class CapituloFenix : IFileMega
{
public const string VERSION = "1.2";
public const int TIEMPOCHECK = 1 * 60 * 1000;
public static TelegramBotClient BotClient { get; set; }
public static SortedList<string, string> DicCapitulosPublished { get; set; }
public static string FileConfig => "config";
public static string File { get; set; }
public static string Web { get; set; }
public static string Canal { get; set;}
public static string ApiKeyBot {get; set;}
public static Semaphore Semaphore { get; set; }
public CapituloFenix(Capitulo capitulo) => Capitulo = capitulo;
public Capitulo Capitulo { get; set; }
public string Name => Capitulo.Name;

static void Main(string[] args)
{
const int TOTAL = 4;
string[] lines;
Timer temporizadorCheck = new Timer(MirarCapitulosNuevos);
DicCapitulosPublished = new SortedList<string, string>();
Semaphore = new Semaphore(1, 1);
if (System.IO.File.Exists(FileConfig))
{
lines = System.IO.File.ReadAllLines(FileConfig);
if (lines.Length != TOTAL)
throw new Exception("el archivo no contiene todos los elementos, File,Web,Canal,ApiKeyBot");
File = lines[0];
Web = lines[1];
Canal = $"@{lines[2]}";
ApiKeyBot = lines[3];
public Uri Picture => Capitulo.Picture;

}
else if (args.Length == 4)
{
File = args[0];
Web = args[1];
Canal = $"@{args[2]}";
ApiKeyBot = args[3];
System.IO.File.WriteAllLines(FileConfig, args);
}else if (args.Length > 0)
{
throw new Exception("se tienen que pasar todos los elementos: File,Web,Canal,ApiKeyBot");
}
else
{
throw new Exception("No se puede iniciar la aplicación!");
}
public string[] GetLinksMega()
{
string linkMega = Capitulo.GetLinkMega();
return Equals(linkMega, default) ? new string[0] : new string[] { linkMega };
}

if (System.IO.File.Exists(File))
{
foreach (string anime in System.IO.File.ReadAllLines(File))
DicCapitulosPublished.Add(anime, anime);
}
}
class Program
{
public const string VERSION = "1.3";
public const int TIEMPOCHECK = 5 * 60 * 1000;

Console.WriteLine($"Iniciando Bot V{VERSION} en Telegram!");
BotClient = new TelegramBotClient(ApiKeyBot);

temporizadorCheck.Change(0, TIEMPOCHECK);
Console.WriteLine("Esperando nuevos capitulos!");

Console.ReadLine();
if (System.IO.File.Exists(File))
{
System.IO.File.Delete(File);
}
System.IO.File.WriteAllLines(File, DicCapitulosPublished.Values);
static void Main(string[] args)
{
Check checkFenix = new Check("Config");
checkFenix.Load(args);
checkFenix.Publicar(() => Capitulo.GetCapitulosHome(checkFenix.Web.AbsoluteUri).Reverse().Select(c => new CapituloFenix(c)),TIEMPOCHECK);

}

private static void MirarCapitulosNuevos(object state)
{
string linkMega;
try
{
Semaphore.WaitOne();
foreach (Capitulo capitulo in Capitulo.GetCapitulosHome(Web).Reverse())
{
if (!DicCapitulosPublished.ContainsKey(capitulo.Name))
{
DicCapitulosPublished.Add(capitulo.Name, capitulo.Name);
linkMega = capitulo.GetLinkMega();
if (!Equals(linkMega, default))
{
BotClient.SendPhotoAsync(Canal, new Telegram.Bot.Types.InputFiles.InputOnlineFile(capitulo.Picture), $"{capitulo.Name} {linkMega}");
Console.WriteLine(capitulo.Name);
}
else DicCapitulosPublished.Remove(capitulo.Name);
}
}
Console.WriteLine("Enter para cerrarlo y guardar");
}
catch { }
finally { Semaphore.Release(); }
}
}
}

0 comments on commit d2d642d

Please sign in to comment.