Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Collections.Generic
  2. Imports System.Linq
  3. Imports System.Text
  4. Imports System.Threading.Tasks
  5. Imports Discord
  6. Imports Discord.Commands
  7.  
  8.  
  9. Public Class config
  10.     Public Team_1 As String
  11.     Public Team_2 As String
  12.     Public currentmapsubmatches As mapsubmatches
  13.     Public allmapsubmatches As mapsubmatches
  14.     Public banned_1 As [String]
  15.     Public banned_2 As [String]
  16.     Public first_submatch As [String]
  17.     Public first_map As [String]
  18.     Public second_submatch As [String]
  19.     Public second_map As [String]
  20.     Public last_submatch As [String]
  21.     Public last_map As [String]
  22.     Public phase As Int32
  23.  
  24.     Public Sub New()
  25.         Team_1 = ""
  26.         Team_2 = ""
  27.         banned_1 = ""
  28.         banned_2 = ""
  29.         first_map = ""
  30.         first_submatch = ""
  31.         second_map = ""
  32.         second_submatch = ""
  33.         last_map = ""
  34.         last_submatch = ""
  35.         phase = 0
  36.         allmapsubmatches = New mapsubmatches
  37.         currentmapsubmatches = New mapsubmatches
  38.     End Sub
  39. End Class
  40.  
  41. Public Class map
  42.     Public name As String
  43.     Public command As String
  44. End Class
  45.  
  46.  
  47. Public Class mapsubmatches
  48.     Public Maps As New List(Of map)
  49.     Public submatches As New List(Of String)
  50.  
  51.     Public Sub New()
  52.         Dim Map1 As New map
  53.         Map1.name = "91°"
  54.         Map1.command = "91"
  55.  
  56.         Dim Map2 As New map
  57.         Map2.name = "Artificial Intelligence"
  58.         Map2.command = "artificial"
  59.  
  60.         Dim Map3 As New map
  61.         Map3.name = "TrackStagram"
  62.         Map3.command = "trackstagram"
  63.  
  64.         Dim Map4 As New map
  65.         Map4.name = "Cozy"
  66.         Map4.command = "cozy"
  67.  
  68.         Dim Map5 As New map
  69.         Map5.name = "Austin"
  70.         Map5.command = "austin"
  71.  
  72.         Maps.Add(Map1)
  73.         Maps.Add(Map2)
  74.         Maps.Add(Map3)
  75.         Maps.Add(Map4)
  76.         Maps.Add(Map5)
  77.  
  78.         Dim Submatch1 As String = "1v1&4v4"
  79.         Dim Submatch2 As String = "2v2&3v3"
  80.         Dim Submatch3 As String = "5v5"
  81.  
  82.         submatches.Add(Submatch1)
  83.         submatches.Add(Submatch2)
  84.         submatches.Add(Submatch3)
  85.     End Sub
  86. End Class
  87.  
  88.  
  89.  
  90.  
  91. Public Class MyBot
  92.     Private discord As DiscordClient
  93.     Private mapsubmatches As New mapsubmatches
  94.     Private ongoingbans As New Dictionary(Of String, config)
  95.  
  96.    
  97.  
  98.  
  99.     ' 0 = PickBan inaktiv, 1= Ban gestartet, 2 = Team A hat die erste Map gebannt, 3 = Team B hat die zweite Map gebannt, 4 = Team A hat das erste Submatch ausgewählt, 5 = Team B hat die erste Map(für das asugewählte Submatch) ausgewählt, 6 = Team B hat das zweite Submatch ausgewählt, 7 = Team A hat die zweite Map ausgewählt
  100.  
  101.  
  102.     Private Function remainingmapnames(current_maps As List(Of map)) As String
  103.         Dim temp As String = ""
  104.         For Each s As map In current_maps
  105.             temp &= s.name & "; "
  106.         Next
  107.         Return temp.Remove(temp.Length - 2, 2)
  108.     End Function
  109.  
  110.     Private Function remainingmapcommands(current_maps As List(Of map)) As String
  111.         Dim temp As String = ""
  112.         For Each s As map In current_maps
  113.             temp &= s.command & "; "
  114.         Next
  115.         Return temp.Remove(temp.Length - 2, 2)
  116.     End Function
  117.  
  118.     Private Function remainingsubmatches(current_submatches As List(Of String)) As String
  119.         Dim temp As String = ""
  120.         For Each s As String In current_submatches
  121.             temp &= s & "; "
  122.         Next
  123.         Return temp.Remove(temp.Length - 2, 2)
  124.     End Function
  125.  
  126.     Public Sub New()
  127.  
  128.  
  129.         Dim temp1 As New DiscordConfigBuilder
  130.         temp1.LogLevel = LogSeverity.Debug
  131.         temp1.LogHandler = AddressOf Log
  132.         discord = New DiscordClient(temp1)
  133.  
  134.  
  135.  
  136.         discord.UsingCommands(Function(x) As CommandServiceConfigBuilder
  137.                                   x.PrefixChar = "!"c
  138.                                   Return x
  139.                               End Function)
  140.  
  141.         discord.GetService(Of CommandService)().CreateCommand("bringbeer").[Do](Async Function(e)
  142.  
  143.                                                                                     Await e.Channel.SendMessage("**Take a :Beer:** " + e.User.Name)
  144.  
  145.                                                                                 End Function)
  146.  
  147.         discord.GetService(Of CommandService)().CreateCommand("pickban2").[Do](Async Function(e)
  148.  
  149.                                                                                    If ongoingbans.ContainsKey(e.Channel.Name) Then
  150.                                                                                        Await e.Channel.SendMessage("There already is an Pick&ban started")
  151.                                                                                    Else
  152.                                                                                        Dim conf As New config
  153.  
  154.                                                                                        Try
  155.                                                                                            Dim temps As String() = Split(e.Channel.Name, "_")
  156.                                                                                            conf.Team_1 = temps(0)
  157.                                                                                            conf.Team_2 = temps(1)
  158.                                                                                        Catch ex As Exception
  159.                                                                                            conf.Team_1 = "Team A"
  160.                                                                                            conf.Team_2 = "Team B"
  161.                                                                                        End Try
  162.  
  163.                                                                                        conf.phase = 1
  164.                                                                                        ongoingbans.Add(e.Channel.Name, conf)
  165.                                                                                        Await e.Channel.SendMessage("**Welcome on the eXeS TC Pick&Ban phase** ! I'm softyBot, here to help you so your Pick&Ban phase goes smoothly. **Team A is gonna be the team with the best groupstage seed** and Team B the other one. You will have **3 minutes** of reflexion between every step of the phase." + System.Environment.NewLine + "The mappack used for this round is : **" + remainingmapnames(mapsubmatches.Maps) + "**." + System.Environment.NewLine + "Submatches used are : ** " + remainingsubmatches(mapsubmatches.submatches) + " **" + System.Environment.NewLine + System.Environment.NewLine + "To ban a map you will have to use the command : **!BAN Name of the map**, so for example : !BAN 91°. To pick a map or a submatche you will have to used : **!PICK Name of the map **or **!PICK 1v1 & 4v4 **." + System.Environment.NewLine + System.Environment.NewLine + "**Let the show begin !**" + System.Environment.NewLine + "**Team A **ban 1 map, please." + System.Environment.NewLine + System.Environment.NewLine + "**Possible commands:** !ban **" + remainingmapcommands(conf.currentmapsubmatches.Maps) + "**" + System.Environment.NewLine + "Team A: " + conf.Team_1 + System.Environment.NewLine + "Team B: " + conf.Team_2)
  166.                                                                                    End If
  167.                                                                                End Function)
  168.  
  169.  
  170.         discord.GetService(Of CommandService)().CreateCommand("stoppickban").[Do](Async Function(e)
  171.                                                                                       If ongoingbans.ContainsKey(e.Channel.Name) Then
  172.                                                                                           ongoingbans.Remove(e.Channel.Name)
  173.                                                                                           Await e.Channel.SendMessage("Currently running Pick&Ban was cancelled!")
  174.                                                                                       Else
  175.                                                                                           Await e.Channel.SendMessage("There is no urrently running Pick&Ban in this Channel")
  176.                                                                                       End If
  177.  
  178.                                                                                   End Function)
  179.  
  180.         discord.GetService(Of CommandService)().CreateGroup("ban", Function(cgb) As CommandGroupBuilder
  181.                                                                        For Each s As map In mapsubmatches.Maps
  182.                                                                            cgb.CreateCommand(s.command).[Do](Async Function(e2)
  183.                                                                                                                  If ongoingbans.ContainsKey(e2.Channel.Name) Then
  184.                                                                                                                      Dim conf As New config
  185.                                                                                                                      ongoingbans.TryGetValue(e2.Channel.Name, conf)
  186.  
  187.                                                                                                                      Select Case conf.phase
  188.                                                                                                                          Case 0
  189.                                                                                                                              Await e2.Channel.SendMessage("Currently there is no ongoing Pick&Ban")
  190.                                                                                                                              Exit Select
  191.                                                                                                                          Case 1
  192.                                                                                                                              conf.banned_1 = s.name
  193.                                                                                                                              conf.phase = 2
  194.                                                                                                                              conf.currentmapsubmatches.Maps.RemoveAll(Function(x) x.name = s.name)
  195.                                                                                                                              Await e2.Channel.SendMessage("**" + conf.Team_1 + "decides to ban " + s.name + ".**" + System.Environment.NewLine + conf.Team_2 + " ban 1 map, please." + System.Environment.NewLine + System.Environment.NewLine + "**Possible commands: **!ban **" + remainingmapcommands(conf.currentmapsubmatches.Maps) + "**")
  196.                                                                                                                              Exit Select
  197.                                                                                                                          Case 2
  198.                                                                                                                              If s.name = conf.banned_1 Then
  199.                                                                                                                                  Await e2.Channel.SendMessage(conf.Team_1 + " already decided to ban " + s.name + ". Please choose a different map to ban")
  200.                                                                                                                              Else
  201.                                                                                                                                  conf.banned_2 = s.name
  202.                                                                                                                                  conf.phase = 3
  203.                                                                                                                                  conf.currentmapsubmatches.Maps.RemoveAll(Function(x) x.name = s.name)
  204.                                                                                                                                  Await e2.Channel.SendMessage("**" + conf.Team_2 + " decides to ban " + s.name + ".**" + System.Environment.NewLine + remainingmapnames(conf.currentmapsubmatches.Maps) + "are the chosen maps for this match." + System.Environment.NewLine + "You now need to pick submatches And the associating maps to them. " + conf.Team_1 + " pick the first submatch, please." + System.Environment.NewLine + System.Environment.NewLine + "**Possible commands:** !pick **" + remainingsubmatches(conf.currentmapsubmatches.submatches) + "**")
  205.                                                                                                                              End If
  206.                                                                                                                              Exit Select
  207.                                                                                                                          Case Else
  208.                                                                                                                              Await e2.Channel.SendMessage("The maps for this match already were banned!")
  209.                                                                                                                              Exit Select
  210.  
  211.                                                                                                                      End Select
  212.                                                                                                                  Else
  213.                                                                                                                      Await e2.Channel.SendMessage("You need to start the pick&ban first!")
  214.                                                                                                                  End If
  215.  
  216.  
  217.                                                                                                              End Function)
  218.  
  219.                                                                        Next
  220.                                                                        Return cgb
  221.                                                                    End Function)
  222.  
  223.         discord.GetService(Of CommandService)().CreateGroup("pick", Function(cgb) As CommandGroupBuilder
  224.                                                                         For Each s As [String] In mapsubmatches.submatches
  225.                                                                             cgb.CreateCommand(s).[Do](Async Function(e2)
  226.                                                                                                           If ongoingbans.ContainsKey(e2.Channel.Name) Then
  227.                                                                                                               Dim conf As New config
  228.                                                                                                               ongoingbans.TryGetValue(e2.Channel.Name, conf)
  229.  
  230.                                                                                                               Select Case conf.phase
  231.                                                                                                                   Case Is < 3
  232.                                                                                                                       Await e2.Channel.SendMessage("You are not ready to pick maps and submatches yet")
  233.                                                                                                                       Exit Select
  234.                                                                                                                   Case 3
  235.                                                                                                                       conf.first_submatch = s
  236.                                                                                                                       conf.currentmapsubmatches.submatches.Remove(s)
  237.                                                                                                                       conf.phase = 4
  238.                                                                                                                       Await e2.Channel.SendMessage("**" + conf.Team_1 + " chose " + s + "** as the first submatch. " + conf.Team_2 + " please select the associating map!" + System.Environment.NewLine + System.Environment.NewLine + "**Possible commands: **!pick **" + remainingmapcommands(conf.currentmapsubmatches.Maps) + "**")
  239.                                                                                                                       Exit Select
  240.                                                                                                                   Case 4
  241.                                                                                                                       Await e2.Channel.SendMessage("You need to pick a map, not a submatch!")
  242.                                                                                                                       Exit Select
  243.                                                                                                                   Case 5
  244.                                                                                                                       If conf.currentmapsubmatches.submatches.Contains(s) Then
  245.                                                                                                                           conf.second_submatch = s
  246.                                                                                                                           conf.currentmapsubmatches.submatches.Remove(s)
  247.                                                                                                                           conf.phase = 6
  248.                                                                                                                           Await e2.Channel.SendMessage("**" + conf.Team_2 + " chose " + s + "** as the second submatch. " + conf.Team_1 + " please select the associating map." + System.Environment.NewLine + System.Environment.NewLine + "**Possible commands: **!pick **" + remainingmapcommands(conf.currentmapsubmatches.Maps) + "**")
  249.                                                                                                                       Else
  250.                                                                                                                           Await e2.Channel.SendMessage("You can't select this submatch.")
  251.                                                                                                                       End If
  252.                                                                                                                       Exit Select
  253.                                                                                                                   Case 6
  254.                                                                                                                       Await e2.Channel.SendMessage("You need to pick a map, not a submatch!")
  255.                                                                                                                       Exit Select
  256.  
  257.                                                                                                                   Case Else
  258.                                                                                                                       Await e2.Channel.SendMessage("The maps for this match already were banned!")
  259.                                                                                                                       Exit Select
  260.  
  261.                                                                                                               End Select
  262.                                                                                                           Else
  263.                                                                                                               Await e2.Channel.SendMessage("You need to start the pick&ban first!")
  264.                                                                                                           End If
  265.                                                                                                       End Function)
  266.  
  267.                                                                         Next
  268.  
  269.                                                                         For Each s As map In mapsubmatches.Maps
  270.                                                                             cgb.CreateCommand(s.command).[Do](Async Function(e2)
  271.                                                                                                                   If ongoingbans.ContainsKey(e2.Channel.Name) Then
  272.                                                                                                                       Dim conf As New config
  273.                                                                                                                       ongoingbans.TryGetValue(e2.Channel.Name, conf)
  274.  
  275.                                                                                                                       Select Case conf.phase
  276.                                                                                                                           Case Is < 3
  277.                                                                                                                               Await e2.Channel.SendMessage("You are not ready to pick maps and submatches yet")
  278.                                                                                                                               Exit Select
  279.                                                                                                                           Case 3
  280.                                                                                                                               Await e2.Channel.SendMessage("You need to pick a submatch, not a map!")
  281.                                                                                                                               Exit Select
  282.                                                                                                                           Case 4
  283.                                                                                                                               If conf.currentmapsubmatches.Maps.Exists(Function(x) x.name = s.name) Then
  284.                                                                                                                                   conf.first_map = s.name
  285.                                                                                                                                   conf.currentmapsubmatches.Maps.RemoveAll(Function(x) x.name = s.name)
  286.                                                                                                                                   conf.phase = 5
  287.                                                                                                                                   Await e2.Channel.SendMessage("**" + conf.Team_2 + " chose " + s.name + "** as first Map. Please also select the second submatch " + conf.Team_2 + "." + System.Environment.NewLine + System.Environment.NewLine + "**Possible commands: **!pick **" + remainingsubmatches(conf.currentmapsubmatches.submatches) + "**")
  288.                                                                                                                               Else
  289.                                                                                                                                   Await e2.Channel.SendMessage("You can't pick this map!")
  290.                                                                                                                               End If
  291.                                                                                                                               Exit Select
  292.                                                                                                                           Case 5
  293.                                                                                                                               Await e2.Channel.SendMessage("You need to pick a submatch, not a map!")
  294.                                                                                                                               Exit Select
  295.                                                                                                                           Case 6
  296.                                                                                                                               If conf.currentmapsubmatches.Maps.Exists(Function(x) x.name = s.name) Then
  297.                                                                                                                                   conf.second_map = s.name
  298.                                                                                                                                   conf.currentmapsubmatches.Maps.RemoveAll(Function(x) x.name = s.name)
  299.                                                                                                                                   conf.last_map = remainingmapnames(conf.currentmapsubmatches.Maps)
  300.                                                                                                                                   conf.last_submatch = remainingsubmatches(conf.currentmapsubmatches.submatches)
  301.                                                                                                                                   conf.phase = 7
  302.                                                                                                                                   Await e2.Channel.SendMessage("**Gratualtions!** You completed the pick&ban and can now play your match! This will be your matchshedule:" + System.Environment.NewLine + System.Environment.NewLine + "First map: " + conf.first_map + " | " + conf.first_submatch + System.Environment.NewLine + "Second map: " + conf.second_map + " | " + conf.second_submatch + System.Environment.NewLine + "Last map: " + conf.last_map + " | " + conf.last_submatch + System.Environment.NewLine + "**GLHF to both Teams!**")
  303.  
  304.                                                                                                                                   ongoingbans.Remove(e2.Channel.Name)
  305.                                                                                                                               Else
  306.                                                                                                                                   Await e2.Channel.SendMessage("You can't pick this map!")
  307.                                                                                                                               End If
  308.                                                                                                                               Exit Select
  309.  
  310.                                                                                                                           Case Else
  311.                                                                                                                               Await e2.Channel.SendMessage("The maps for this match already were banned!")
  312.                                                                                                                               Exit Select
  313.  
  314.                                                                                                                       End Select
  315.                                                                                                                   Else
  316.                                                                                                                       Await e2.Channel.SendMessage("You need to start the pick&ban first!")
  317.                                                                                                                   End If
  318.                                                                                                               End Function)
  319.  
  320.                                                                         Next
  321.                                                                         Return cgb
  322.                                                                     End Function)
  323.  
  324.         discord.ExecuteAndWait(Async Function()
  325.                                    Await discord.Connect("I won't show you this part ofc =P", TokenType.Bot)
  326.  
  327.                                End Function)
  328.  
  329.  
  330.  
  331.     End Sub
  332.  
  333.     Private Sub Log(sender As Object, e As LogMessageEventArgs)
  334.         Console.WriteLine(e.Message)
  335.     End Sub
  336.  
  337. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement