A Bolton man spat at a police officer after being arrested and was found to be in possession of cannabis.
Police were called to Deansgate in the centre of the town at around 2.30am.
Bolton Magistrates Court heard there had been a fight outside the Old Three Crowns Pub.
David Moody was arrested at the scene.
The 27-year-old was taken to Bolton custody suite during the incident on May 5.
Henry Prescott, prosecuting, said: “The defendant continuously displayed aggressive behaviour.
“He was verbally abusive towards officers at Bolton Custody Suite.”
He said he “spat at the face” of a special constable who was there and it collided with him.
Moody, from Whalley Avenue, Bolton, was later searched and a snap bag of cannabis was found on him.
At court he pleaded guilty to the assault of an emergency worker and possession of cannabis.
Mr Prescott said he had not been in trouble since April 2018 and that was for dissimilar offences.
Joshelle Holgate, defending, said: “Mr Moody has entered a guilty plea at the first opportunity and I would ask for full credit.
“The offences which he commmited were out of character.
“He accepts that he has drank to excess.
“He does not recollect what happened.
“I do not use drinking as an excuse.
“After being told he committed the offence in interview he apologised immediately.
“In the report he does show remorse.”
She said at the time of the offence he was registered as homeless but since then he had approached the council and they had found him accommodation.
Chair of the bench Stephen Paine imposed a community order to last for 18 months.
As part of this he ordered Moody to complete 30 rehabilitation activity requirement days and to do 80 hours of unpaid work.
He also ordered him to pay £100 in compensation to the police officer he attacked.