Skip to content

Commit

Permalink
added custom logic to remove hal joining channel for audio commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphisor committed Feb 12, 2019
1 parent 933dd8c commit 5adff1d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion HalDiscordBot.Core/CustomLogic/LogicExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class LogicExecutor
public static void Exec(LogicType type, string methodName, object[] args, ISocketMessageChannel currentChannel)
{
var types = Assembly.GetExecutingAssembly().GetTypes();
var logics = types.Where(tp => tp.IsClass && tp.Namespace == $"HalDiscordBot.Core.CustomLogic.{type.ToString()}" && tp.Attributes == TypeAttributes.Public);
var logics = types.Where(tp => tp.IsClass && tp.Namespace == $"HalDiscordBot.Core.CustomLogic.{type.ToString()}" && tp.IsPublic);
foreach (var logic in logics)
{
var ctor = logic.GetConstructor(new Type[] { typeof(ISocketMessageChannel) });
Expand Down
46 changes: 46 additions & 0 deletions HalDiscordBot.Core/CustomLogic/UserUpdated/HalAudioUserUpdated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Discord.WebSocket;
using HalDiscordBot.Core.CustomLogic.Bases;
using System;
using System.Collections.Generic;
using System.Linq;

namespace HalDiscordBot.Core.CustomLogic.UserUpdated
{
public class HalAudioUserUpdated : UserUpdatedLogic
{
public HalAudioUserUpdated(ISocketMessageChannel currentChannel) : base(currentChannel)
{
}

public override void UserJoined(string user)
{
RemoveLog(user);
}

public override void UserLeft(string user)
{
RemoveLog(user);
}

public override void UserMoved(string userName, string from, string to)
{
if (from != "KickChannel" && to != "KickChannel")
RemoveLog(userName);
}

private void RemoveLog(string userName)
{
if (userName == "HAL")
{
var message = _currentChannel.GetMessagesAsync(3).ToList();
var transformed = message.GetAwaiter().GetResult().SelectMany(msg => msg);
if(transformed.Any(msg => msg.Content.Contains("$a")))
{
var hallogs = transformed.Where(msg => msg.Author.Username == "HAL");
var task = _currentChannel.DeleteMessagesAsync(hallogs);
task.GetAwaiter().GetResult();
}
}
}
}
}

0 comments on commit 5adff1d

Please sign in to comment.