public async Task Start() { // client.SetGameAsync("Type !?help for help"); string token; #if DEBUG token = Path.Combine(System.Windows.Forms.Application.StartupPath, "config_debug.token"); #else token = Path.Combine(System.Windows.Forms.Application.StartupPath, "config.token"); #endif var tokar = File.ReadAllLines(token); string tok = ""; foreach (var t in tokar) { tok += t; } BotToken bttoken = JsonConvert.DeserializeObject <BotToken>(tok); await client.LoginAsync(TokenType.Bot, bttoken.Token); await client.StartAsync(); await Task.Delay(-1); }
internal static ITelegramBotClient GetTelegramBotClient() { if (telegramBotClient == null) { telegramBotClient = new TelegramBotClient(BotToken.Get()); } return(telegramBotClient); }
private ModulesManager() { telegramBotClient = new TelegramBotClient(BotToken.Get()); messageManager = new MessageManager(); sessionManager = new SessionManager(); userManager = new UserManager(); secureManager = new SecureManager(); databaseManager = new DatabaseManager(); }
public override int GetHashCode() { int hash = 17; hash += (hash * 31) + (!string.IsNullOrEmpty(Name) ? Name.GetHashCode() : 0); hash += (hash * 31) + (!string.IsNullOrEmpty(BotToken) ? BotToken.GetHashCode() : 0); hash += (hash * 31) + Id.GetHashCode(); return(hash); }
private static Bucket GetSharedBucket(ILogger logger, BotToken token, GatewayPayloadOperation operation, int uses, TimeSpan resetDelay) { var dictionary = _sharedBuckets.GetOrAdd(token.Id, _ => new SynchronizedDictionary <GatewayPayloadOperation, Bucket>(1)); var bucket = dictionary.GetOrAdd(operation, (_, tuple) => { var(logger, uses, resetDelay) = tuple; return(new Bucket(logger, uses, resetDelay)); }, (logger, uses, resetDelay)); return(bucket); }
private static void ParseArgs(string[] args) { if (args == null || args.Length == 0) { return; } if (args.Length >= 1 && !string.IsNullOrEmpty(args[0])) { BotToken.Set(args[0]); } }
public bool Equals(TelegramConversation other) { return(other == null ? false : Name.Equals(other.Name, StringComparison.InvariantCultureIgnoreCase) && BotToken.Equals(other.BotToken, StringComparison.InvariantCultureIgnoreCase) && Id == other.Id); }
public static void ConfigureDiscordClient(this IServiceCollection services, HostBuilderContext context, DiscordClientHostingContext discordContext) { if (!services.Any(x => x.ServiceType == typeof(Token))) { var token = new BotToken(discordContext.Token); services.AddToken(token); } if (discordContext.Intents != null) { services.Configure <DefaultGatewayApiClientConfiguration>(x => x.Intents = discordContext.Intents.Value); } services.Configure <DefaultGatewayDispatcherConfiguration>(x => x.ReadyEventDelayMode = discordContext.ReadyEventDelayMode); services.AddHostedService <DiscordClientMasterService>(); var serviceAssemblies = discordContext.ServiceAssemblies; if (serviceAssemblies != null) { for (var i = 0; i < serviceAssemblies.Count; i++) { var types = serviceAssemblies[i].GetExportedTypes(); foreach (var type in types) { if (type.IsAbstract) { continue; } if (!typeof(DiscordClientService).IsAssignableFrom(type)) { continue; } var hasService = false; for (var j = 0; j < services.Count; j++) { var service = services[j]; if (service.ServiceType == type || service.ServiceType == typeof(IHostedService) && service.GetImplementationType() == type) { hasService = true; break; } } if (hasService) { continue; } services.AddSingleton(type); services.AddSingleton(typeof(DiscordClientService), x => x.GetService(type)); services.AddSingleton(typeof(IHostedService), x => x.GetService(type)); } } } if (discordContext.Status != null || discordContext.Activities != null) { services.Configure <DefaultGatewayApiClientConfiguration>(x => x.Presence = new UpdatePresenceJsonModel { Status = discordContext.Status ?? UserStatus.Online, Activities = discordContext.Activities?.Select(x => x.ToModel()).ToArray() ?? Array.Empty <ActivityJsonModel>() }); } }