Skip to content

Commit

Permalink
Merge branch 'release/0.4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallimathias committed Nov 25, 2018
2 parents 6252eac + 617a13a commit 698d77a
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 76 deletions.
12 changes: 8 additions & 4 deletions BotMaster/BotMaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<FileVersion>0.2.0.0</FileVersion>
<Version>0.2.0</Version>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<FileVersion>0.3.0.0</FileVersion>
<Version>0.3.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NLog" Version="4.5.11" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NoobDevBot.Telegram\NoobDevBot.Telegram.csproj" />
<ProjectReference Include="..\WarFabrik.Clone\WarFabrik.Clone.csproj" />
Expand Down
28 changes: 25 additions & 3 deletions BotMaster/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using NoobDevBot.Telegram;
using NLog;
using NLog.Config;
using NLog.Targets;
using NoobDevBot.Telegram;
using System;
using System.IO;
using System.Threading;
using WarFabrik.Clone;
using static WarFabrik.Clone.FollowerServiceNew;
Expand All @@ -8,12 +12,30 @@ namespace BotMaster
{
class Program
{
private static Logger logger;
private static ManualResetEvent manualReset;
private static Bot twitchBot;
private static TelegramBot telegramBot;

static void Main(string[] args)
{
var config = new LoggingConfiguration();

var info = new FileInfo(Path.Combine(".", "additionalfiles", "botmaster.log"));

if (!info.Directory.Exists)
info.Directory.Create();

#if DEBUG
config.AddRule(LogLevel.Debug, LogLevel.Fatal, new ColoredConsoleTarget("botmaster.logconsole"));
config.AddRule(LogLevel.Trace, LogLevel.Fatal, new FileTarget("botmaster.logfile") { FileName = info.FullName });
#else
config.AddRule(LogLevel.Info, LogLevel.Fatal, new FileTarget("botmaster.logfile") { FileName = info.FullName });
#endif
LogManager.Configuration = config;
logger = LogManager.GetCurrentClassLogger();


manualReset = new ManualResetEvent(false);

telegramBot = new TelegramBot();
Expand All @@ -24,8 +46,8 @@ static void Main(string[] args)
twitchBot.FollowerService.OnNewFollowersDetected += TwitchNewFollower;
twitchBot.OnHosted += TwitchBotOnHosted;
Console.CancelKeyPress += ConsoleCancelKeyPress;
logger.Info("Der Bot ist Online");
telegramBot.SendMessageToGroup("NoobDev", "Der Bot ist Online");
//Console.ReadKey();
manualReset.WaitOne();

}
Expand All @@ -35,7 +57,7 @@ private static void TwitchBotOnHosted(object sender, (string Name, int Count) e)

private static void ConsoleCancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
Console.WriteLine("Quit Bot master");
logger.Info("Quit Bot master");
telegramBot.Exit();
twitchBot.Disconnect();
manualReset.Set();
Expand Down
12 changes: 7 additions & 5 deletions NoobDevBot.Telegram/NoobDevBot.Telegram.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>0.2.0</Version>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>0.3.0</Version>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<FileVersion>0.3.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandManagementSystem" Version="3.0.0-alpha2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1" />
<PackageReference Include="Telegram.Bot" Version="14.9.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="NLog" Version="4.5.11" />
<PackageReference Include="Telegram.Bot" Version="14.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 12 additions & 2 deletions NoobDevBot.Telegram/TelegramBot.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using NLog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand All @@ -12,12 +14,20 @@ namespace NoobDevBot.Telegram
{
public class TelegramBot
{
private readonly Logger logger;
private TelegramBotClient bot;
private TelegramCommandManager manager;

public TelegramBot()
{
bot = new TelegramBotClient(System.IO.File.ReadAllText(@".\Telegram_Token.txt"));
logger = LogManager.GetCurrentClassLogger();

var info = new FileInfo(Path.Combine(".", "additionalfiles", "Telegram_Token.txt"));

if (!info.Directory.Exists)
info.Directory.Create();

bot = new TelegramBotClient(System.IO.File.ReadAllText(info.FullName));
manager = new TelegramCommandManager();
DatabaseManager.Initialize();
//DatabaseManager.CreateGroup("NoobDev");
Expand Down
14 changes: 10 additions & 4 deletions NoobDevBot.Telegram/TelegramBotContext.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Microsoft.EntityFrameworkCore;
using NoobDevBot.Telegram.DatabaseModels;
using System.IO;

namespace NoobDevBot.Telegram
{
public class TelegramBotContext: DbContext
public class TelegramBotContext : DbContext
{
public DbSet<NoobUser> User { get; set; }
public DbSet<Stream> Streams { get; set; }
public DbSet<DatabaseModels.Stream> Streams { get; set; }
public DbSet<Right> Rights { get; set; }
public DbSet<Group> Groups{ get; set; }
public DbSet<Group> Groups { get; set; }
public DbSet<GroupChat> GroupChat { get; set; }
public DbSet<User_Right> User_Right { get; set; }
public DbSet<Group_User> Group_User { get; set; }
Expand All @@ -17,7 +18,12 @@ public class TelegramBotContext: DbContext

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=telegram.db");
var info = new FileInfo(Path.Combine(".", "additionalfiles", "telegram.db"));

if (!info.Directory.Exists)
info.Directory.Create();

optionsBuilder.UseSqlite($"Data Source={info.FullName}");
}
}
}
41 changes: 23 additions & 18 deletions WarFabrik.Clone/Bot.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommandManagementSystem;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NLog;
using System;
using System.Drawing;
using System.IO;
Expand All @@ -11,6 +12,7 @@
using TwitchLib.Client;
using TwitchLib.Client.Events;
using TwitchLib.Client.Models;
using TwitchLib.Communication.Events;
using static WarFabrik.Clone.FollowerServiceNew;

namespace WarFabrik.Clone
Expand All @@ -28,42 +30,47 @@ public class Bot
private TwitchClient client;
private JoinedChannel initialChannel;

private readonly Logger<TwitchClient> logger;

private TwitchAPI api;
private readonly Logger logger;

public Bot()
{
var tokenFile = JsonConvert.DeserializeObject<TokenFile>(File.ReadAllText(@".\Token.json"));
logger = LogManager.GetCurrentClassLogger();
var info = new FileInfo(Path.Combine(".", "additionalfiles", "Token.json"));

if (!info.Directory.Exists)
info.Directory.Create();

var tokenFile = JsonConvert.DeserializeObject<TokenFile>(File.ReadAllText(info.FullName));
Manager = new BotCommandManager();
logger = new Logger<TwitchClient>(new LoggerFactory());
api = new TwitchAPI();
api.Settings.ClientId = tokenFile.ClientId;
api.Settings.AccessToken = tokenFile.Token;

var credentials = new ConnectionCredentials(tokenFile.Name, tokenFile.OAuth);
//client = new TwitchClient(credentials, channel: "NoobDevTv", logging: true, logger: logger);
client = new TwitchClient(logger: logger);
client = new TwitchClient();
client.Initialize(credentials, channel: "NoobDevTv", autoReListenOnExceptions: true);

bool initialId = true;
do
{
try
{
ChannelId = api.Users.v5.GetUserByNameAsync("NoobDevTv").Result.Matches.First().Id;
ChannelId = api.V5.Users.GetUserByNameAsync("NoobDevTv").Result.Matches.First().Id;
initialId = false;
}
catch (Exception ex)
{
logger.LogError($"{ex.GetType().Name}: {ex.Message}");
logger.Error($"{ex.GetType().Name}: {ex.Message}");
initialId = true;
Thread.Sleep(1000);
}

} while (initialId);

FollowerService = new FollowerServiceNew(api, ChannelId, 10000, logger: logger);
FollowerService = new FollowerServiceNew(api, ChannelId, 10000);

client.OnConnected += ClientOnConnected;
client.OnDisconnected += ClientOnDisconnected;
Expand All @@ -74,7 +81,7 @@ public Bot()
FollowerService.OnNewFollowersDetected += FollowerServiceOnNewFollowersDetected;

}

public void Connect()
{
client.Connect();
Expand All @@ -87,18 +94,16 @@ public void FollowerServiceOnNewFollowersDetected(object sender, NewFollowerDete
{
foreach (var item in e.NewFollowers)
{
var tempColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(item.User.DisplayName + " has followed and ");
var msg = item.User.DisplayName + " has followed and ";

if (item.Notifications)
Console.WriteLine("wants to be notified");
msg += "wants to be notified";
else
Console.WriteLine("doesn't like to be notified");
msg += "doesn't like to be notified";

Console.ForegroundColor = tempColor;
logger.Info(msg);

client.SendMessage(initialChannel, $"Der {item.User.DisplayName} hat sich verklickt. Vielen lieben dank dafür <3");
client.SendMessage(initialChannel, $"{item.User.DisplayName} hat sich verklickt. Vielen lieben dank dafür <3");
Manager.Dispatch("hype", new BotCommandArgs(this, api, null));
}

Expand Down Expand Up @@ -126,15 +131,15 @@ private void ClientOnMessageReceived(object sender, OnMessageReceivedArgs e)

private void ClientOnConnected(object sender, OnConnectedArgs e)
{
//logger.Info("Connected to Twitch Channel {Channel}");
logger.Info($"Connected to Twitch Channel");
initialChannel = client.JoinedChannels.FirstOrDefault();
FollowerService.StartService();
client.SendMessage(initialChannel, $"Bot is Online...");
}

private void ClientOnDisconnected(object sender, OnDisconnectedArgs e)
private void ClientOnDisconnected(object sender, OnDisconnectedEventArgs e)
{
//logger.Info("Bot disconnect");
logger.Info("Bot disconnect");
client.SendMessage(initialChannel, "Ich gehe in den Standby bb");
}

Expand Down
4 changes: 2 additions & 2 deletions WarFabrik.Clone/Commands/SimpleCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static bool WhoAmI(BotCommandArgs args)
private static async Task<bool> AsyncStuff(BotCommandArgs args)
{
string result = "";
var user = await args.TwitchAPI.Users.v5.GetUserByIDAsync(args.Message.UserId);
var user = await args.TwitchAPI.V5.Users.GetUserByIDAsync(args.Message.UserId);

if (user == null)
{
Expand Down Expand Up @@ -166,7 +166,7 @@ private static async Task<bool> AsyncStuff(BotCommandArgs args)

private static async Task<bool> UptimeAsync(BotCommandArgs args)
{
var uptime = await args.TwitchAPI.Streams.v5.GetUptimeAsync(args.Message.RoomId);
var uptime = await args.TwitchAPI.V5.Streams.GetUptimeAsync(args.Message.RoomId);

if (uptime == null)
{
Expand Down
23 changes: 0 additions & 23 deletions WarFabrik.Clone/ConsoleLogger.cs

This file was deleted.

Loading

0 comments on commit 698d77a

Please sign in to comment.