Make birthdays add/deleteable by self
This commit is contained in:
		
							parent
							
								
									f0c7c99627
								
							
						
					
					
						commit
						076dc16e03
					
				
										
											Binary file not shown.
										
									
								
							| @ -115,23 +115,25 @@ namespace DiscoBot.bdaygreet | |||||||
|         private async Task HandleBDayAddCommand(SocketMessage msg, string[] parameters) |         private async Task HandleBDayAddCommand(SocketMessage msg, string[] parameters) | ||||||
|         { |         { | ||||||
|             var gauthor = guild.Users.Where(u => u.Id == msg.Author.Id).Single(); |             var gauthor = guild.Users.Where(u => u.Id == msg.Author.Id).Single(); | ||||||
|             if(!gauthor.GuildPermissions.Administrator) |  | ||||||
|             { |  | ||||||
|                 await msg.Channel.SendMessageAsync("Sorry only administrators can add birthdays :("); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|             var gchan = msg.Channel as IGuildChannel; |  | ||||||
|             string name = parameters[1]; |             string name = parameters[1]; | ||||||
|             string date = parameters[2]; |             string date = parameters[2]; | ||||||
|             SocketGuildUser user; |             SocketGuildUser user; | ||||||
|             try { |             try | ||||||
|             var id = MentionUtils.ParseUser(name); |             { | ||||||
|             user = guild.Users.Where(u => u.Id == id).Single(); |                 var id = MentionUtils.ParseUser(name); | ||||||
|             } catch(Exception) |                 user = guild.Users.Where(u => u.Id == id).Single(); | ||||||
|  |             } | ||||||
|  |             catch (Exception) | ||||||
|             { |             { | ||||||
|                 await msg.Channel.SendMessageAsync("I can't find user " + name + " so I can't add them."); |                 await msg.Channel.SendMessageAsync("I can't find user " + name + " so I can't add them."); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |             if (gauthor.Id != user.Id && !gauthor.GuildPermissions.Administrator) | ||||||
|  |             { | ||||||
|  |                 await msg.Channel.SendMessageAsync("Only administrators can add arbitrary birthdays. You can add your own though! :)"); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |             var gchan = msg.Channel as IGuildChannel; | ||||||
|             DateTimeOffset d; |             DateTimeOffset d; | ||||||
|             try { |             try { | ||||||
|                 d = DateTimeOffset.ParseExact(date,new string[] { "dd.MM.", "d.MM.", "dd.M", "d.M." }, null, DateTimeStyles.AssumeUniversal); |                 d = DateTimeOffset.ParseExact(date,new string[] { "dd.MM.", "d.MM.", "dd.M", "d.M." }, null, DateTimeStyles.AssumeUniversal); | ||||||
| @ -201,13 +203,14 @@ namespace DiscoBot.bdaygreet | |||||||
|         private async Task HandleBDayDelCommand(SocketMessage msg, string[] parameters) |         private async Task HandleBDayDelCommand(SocketMessage msg, string[] parameters) | ||||||
|         { |         { | ||||||
|             var gauthor = guild.Users.Where(u => u.Id == msg.Author.Id).Single(); |             var gauthor = guild.Users.Where(u => u.Id == msg.Author.Id).Single(); | ||||||
|             if (!gauthor.GuildPermissions.Administrator) |              | ||||||
|             { |  | ||||||
|                 await msg.Channel.SendMessageAsync("Sorry only administrators can delete birthdays :("); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|             var gchan = msg.Channel as IGuildChannel; |             var gchan = msg.Channel as IGuildChannel; | ||||||
|             string tag = ((IModule)this).ConcatParameters(parameters[1..]); |             string tag = ((IModule)this).ConcatParameters(parameters[1..]); | ||||||
|  |             if (tag != msg.Author.Username+"#"+msg.Author.DiscriminatorValue && !gauthor.GuildPermissions.Administrator) | ||||||
|  |             { | ||||||
|  |                 await msg.Channel.SendMessageAsync("Only administrators can delete arbitrary birthdays. You can delete your own..."); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 var b = bdayGreetContext.BDays.Where(b => b.DiscordTag == tag).Single(); |                 var b = bdayGreetContext.BDays.Where(b => b.DiscordTag == tag).Single(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user