public async Task OnChannelCreate(SocketChannel channel) { Console.WriteLine(channel.ToString()); }
public async Task SendMessageToChannel ( [Remainder, Summary("remainder -> args")] string args ) { bool is_debug = false; Discord.WebSocket.ISocketMessageChannel channel = null; SocketChannel sChannel = null; List <string> msgList = new List <string>(); string msg; string[] elements = args.Split(); int[] msgList_index_has_mentions = new int[100]; int index_array_count = 0; for (int i = 0; i < elements.Length; i++) { #if TRACE Console.WriteLine("*_ elements[" + i + "]: " + elements[i]); #endif switch (elements[i]) { case "-c": case "-channel": #if TRACE Console.WriteLine("+ Detected channel modification"); #endif ulong channelID; ulong.TryParse(elements[++i], out channelID); sChannel = Program.client.GetChannel(channelID); channel = (Discord.WebSocket.ISocketMessageChannel)sChannel; #if TRACE Console.WriteLine("+ Channel sending: (sChannel): " + sChannel.ToString() + ", (channel): " + channel.Name); #endif break; case "-d": case "-debug": is_debug = true; #if TRACE Console.WriteLine("+ Will reply debug"); #endif break; default: msgList.Add(elements[i]); #if TRACE Console.WriteLine("+ msgList new element: " + elements[i]); #endif //smart_mention if (elements[i].StartsWith(bot_conf.mention_prefix)) { msgList_index_has_mentions[index_array_count++] = msgList.Count - 1; #if TRACE Console.WriteLine("Assigned msgList_ind[" + (index_array_count - 1) + "] = " + msgList.Count); #endif } break; } } if (index_array_count > 0 && channel != null) { //Set up dictionary Dictionary <string, SocketUser> lookup_table = new Dictionary <string, SocketUser>(); SocketUser[] users = sChannel.Users.ToArray(); for (int i = 0; i < users.Length; i++) { string username = users[i].Username.ToLower(); #if TRACE Console.WriteLine("*_+_* Username in channel " + channel.Name + ": " + username); #endif lookup_table[username] = users[i]; lookup_table[username + "#" + users[i].Discriminator] = users[i]; #if TRACE Console.WriteLine("lookup_table[" + username + "] = (SocketUser)" + users[i].ToString()); Console.WriteLine("lookup_table[" + (username + "#" + users[i].Discriminator) + "] = (SocketUser)" + users[i].ToString()); #endif } //replace user's mention with correct mention for (int j = 0; j < index_array_count; j++) { int index = msgList_index_has_mentions[j]; #if TRACE Console.WriteLine("initial message: " + msgList[index]); #endif string[] all_mentions = msgList[index].Split('@', StringSplitOptions.RemoveEmptyEntries); #if TRACE Console.WriteLine("all_mentions: { " + (string.Join(", ", all_mentions)) + "}"); #endif for (int i = 0; i < all_mentions.Length; i++) { SocketUser user = lookup_table[all_mentions[i].ToLower()]; if (user != null) { all_mentions[i] = user.Mention; } else { all_mentions[i] = "@" + all_mentions[i]; } } msgList[index] = string.Join(" ", all_mentions); #if TRACE Console.WriteLine("after smart: " + msgList[index]); #endif } } msg = string.Join(' ', msgList); if (is_debug) { if (channel == null) { await ReplyAsync("Channel is null, meaning message will be sent on current channel"); } else { await ReplyAsync("Channel name:" + channel.Name + "; Channel ID: " + channel.Id + "; Channel is NSFW:" + channel.IsNsfw + "; Msg: " + msg); } } if (channel == null) { await ReplyAsync(msg); } else { await channel.SendMessageAsync(msg); } }