Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. SocketTextChannel channel = message.Channel as SocketTextChannel;
  2.             ulong serverId = channel.Guild.Id;
  3.  
  4.             if (parameterMessage.Content.Equals(".prefix"))
  5.             {
  6.  
  7.                 SQLiteConnection conn = new SQLiteConnection(Strings.PREFIXES_CONNECTIONSTRING);
  8.                 conn.Open();
  9.  
  10.                 string sql = "SELECT * FROM prefixes WHERE serverid='{0}'";
  11.                 string sqlFormatted = string.Format(sql, serverId);
  12.  
  13.                 SQLiteCommand command = new SQLiteCommand(sqlFormatted, conn);
  14.                 SQLiteDataReader rdr = command.ExecuteReader();
  15.  
  16.                 while (rdr.Read())
  17.                 {
  18.  
  19.                     await channel.SendMessageAsync("The prefix for this server is " + rdr["prefix"]);
  20.  
  21.                 }
  22.  
  23.                 conn.Close();
  24.  
  25.                 return;
  26.  
  27.             }
  28.  
  29.             // Lookup the prefix for the server
  30.             SQLiteConnection connection = new SQLiteConnection(Strings.PREFIXES_CONNECTIONSTRING);
  31.             connection.Open();
  32.  
  33.             SQLiteDataReader reader = null;
  34.             string prefix = null;
  35.  
  36.             try {
  37.                 string query = "SELECT * FROM prefixes WHERE serverid='{0}'";
  38.                 string queryFormatted = string.Format(query, serverId);
  39.  
  40.                 SQLiteCommand command = new SQLiteCommand(queryFormatted, connection);
  41.                 reader = command.ExecuteReader();
  42.                
  43.  
  44.             } catch (Exception e)
  45.             {
  46.  
  47.                 Console.WriteLine(e.Message);
  48.                
  49.             }
  50.  
  51.             while (reader.Read())
  52.             {
  53.  
  54.                 prefix = reader["prefix"].ToString();
  55.  
  56.             }
  57.  
  58.             if (prefix == null)
  59.             {
  60.  
  61.                 prefix = ".";
  62.  
  63.             }
  64.  
  65.             connection.Close();
  66.  
  67.             if (!message.HasStringPrefix(prefix, ref argPos)) return;
  68.  
  69.  
  70.  
  71.             // Create a Command Context
  72.             var context = new CommandContext(client, message);
  73.             // Execute the Command, store the result
  74.             var result = await commands.ExecuteAsync(context, argPos, map);
  75.  
  76.             StatsService.CommandsRan++;
  77.  
  78.             // If the command failed, notify the user
  79.             if (!result.IsSuccess)
  80.             {
  81.  
  82.                 EmbedBuilder builder = new EmbedBuilder();
  83.                 builder.Color = Colours.ERROR;
  84.                 builder.Title = "Error";
  85.                 builder.Description = result.ErrorReason;
  86.  
  87.                 await message.Channel.SendMessageAsync("", false, builder);
  88.                
  89.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement