Coverage for cmds/echo.py: 53%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

15 statements  

1""" 

2echo.py 

3 

4contains echo() and echoa() 

5""" 

6 

7import datetime 

8import error 

9import database 

10 

11async def echo(message, *args): 

12 """ 

13 echo() 

14 

15 echos message 

16 """ 

17 

18 # check for arguments: 

19 if args: 

20 return f"`{message.author}:` {' '.join(args)}" 

21 

22 raise error.ArgumentRequiredError 

23 

24async def echoa(message, *args): 

25 """ 

26 echoa() 

27 

28 echos message anonymously 

29 """ 

30 

31 # get admins from database 

32 admins = database.get("admins") 

33 

34 # check for priviledges 

35 if any([ 

36 str(message.author.id) in admins, 

37 message.channel.permissions_for(message.author).administrator, 

38 ]): 

39 

40 if args: 

41 database.write("echoa", str(message.id), string='\n'.join([ 

42 f"{datetime.datetime.now()}", 

43 f"{message.guild.id}: {message.guild.name}", 

44 f"{message.channel.id}: {message.channel.name}", 

45 f"{message.author.id}: {message.author}", 

46 f"{' '.join(args)}", 

47 ])) 

48 return ' '.join(args) 

49 

50 raise error.ArgumentRequiredError 

51 

52 raise error.AuthorisationError